悬棺求调(10)
查看原帖
悬棺求调(10)
1293810
chym_ddxy_qqzq_yysy楼主2025/7/28 10:43
#include<bits/stdc++.h>
#define endl '\n'

using namespace std;
const int maxn=1e6+1;

int n,m,q;
struct node {
	int d,b1,b,f;
	vector<int>e;
} v[maxn];

void read() {
	cin>>n;
	for(int i=1; i<=n; i++) {
		cin>>v[i].d;
	}
	for(int i=1,x,y; i<=n-1; i++) {
		cin>>x>>y;
		v[x].e.emplace_back(y),v[y].e.emplace_back(x);
	}
}

void csh(int x) {
	v[x].b1=1;
	for(auto i:v[x].e) {
		if(!v[i].b1) {
			v[i].f=x;
			csh(i);
		}
	}
}

void f1(int x,int d) {
	v[x].d+=d;
	v[x].b=1;
	for(auto i:v[x].e) {
		if(!v[i].b&&v[x].f!=i)
			f1(i,d);
	}
}

void f2(int x,int d) {
	v[x].d+=d;
	for(auto i:v[x].e) {
		v[i].d+=d;
	}
}

void print() {
	cin>>q;
	for(int i=1,t; i<=q; i++) {
		cin>>t;
		cout<<v[t].d<<endl;
	}
}

signed main() {
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	read();
	csh(1);
	cin>>m;
	while(m--) {
		int t,x,y;
		cin>>t>>x>>y;
		if(t==1) {
			f1(x,y);
		} else f2(x,y);
	}
	print();
	return 0;
}
2025/7/28 10:43
加载中...