比赛 |
20161116 |
评测结果 |
AAAATTTTTT |
题目名称 |
新型武器 |
最终得分 |
40 |
用户昵称 |
Riolu |
运行时间 |
6.010 s |
代码语言 |
C++ |
内存使用 |
4.89 MiB |
提交时间 |
2016-11-16 11:11:57 |
显示代码纯文本
/*=========================================*
* Auther: Riolu
* Time: 2016.11.16
* ©Copyright 2016 Riolu. All Rights Reserved.
*=========================================*/
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
//#include<cmath>
#include<string>
//#include<ctime>
#include<cstring>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef double db;
const int N =3e5+1;
int n,k;
int v[N];
vector<int> son[N];
int Q(int rt,int c,int d){
int ans=0,i,l=son[rt].size();
if(d==c)return v[rt];
for(i=0;i<l;i++)ans+=Q(son[rt][i],c,d+1);
return ans;
}
void read(){
scanf("%d",&n);
int i,fa,to,t,t1,t2;
for(i=1;i<=n;i++)scanf("%d",&v[i]);
for(i=1;i<n;i++){
scanf("%d%d",&fa,&to);
son[fa].push_back(to);
}
scanf("%d",&k);
for(i=1;i<=k;i++){
scanf("%d%d%d",&t,&t1,&t2);
if(t==1)v[t1]=t2;
else printf("%d\n",Q(t1,t2,0));
}
}
int main(){
freopen("newweapon.in","r",stdin);
freopen("newweapon.out","w",stdout);
read();
fclose(stdin);fclose(stdout);
return 0;
}