| 比赛 | 20161116 | 评测结果 | WWWWWWWWWW | 
    | 题目名称 | 新型武器 | 最终得分 | 0 | 
    | 用户昵称 | 24193 | 运行时间 | 1.994 s | 
    | 代码语言 | C++ | 内存使用 | 8.33 MiB | 
    | 提交时间 | 2016-11-16 12:12:17 | 
显示代码纯文本
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
using namespace std;
int n,q,a,u,c;
int i,j,l,ans=0;
struct tree{
	int v;
	int d;
	int lian;
	int z[2];
}t[300001];
struct bian{
	int fr,to;
}b[300001];
int main()
{
	freopen("newweapon.in","r",stdin);
	freopen("newweapon.out","w",stdout);
	cin>>n>>q;
	for(i=0;i<n;i++)
	  {
	  	cin>>t[i].v;
	  }
	for(i=0;i<n-1;i++)
	  {
	  	cin>>b[i].fr>>b[i].to;
	  	t[b[i].fr].lian++;
	  	t[b[i].fr].z[t[b[i].fr].lian]=b[i].to;
	  	t[b[i].to].d++;
	  }
	for(l=0;l<q;l++)
	  {
	  	cin>>a>>u>>c;
	  	if(a==1)
	  	  {
	  	  	t[u].v=c;
	  	  }
	  	if(a==2)
	  	  {
	  	  	for(j=0;j<n;j++)
	  	  	  {
	  	  	  	if(t[j].d-t[u].d==c)
	  	  	  	  ans+=t[j].v;
	  	  	  }
	  	  }
	  	cout<<ans<<endl;
	  }
	fclose(stdin);fclose(stdout);
	return 0;
}