10分!!求调!急!
查看原帖
10分!!求调!急!
1293628
Walym_xIa楼主2025/7/28 09:40
#include<bits/stdc++.h>
using namespace std;
#define int long long

const int maxn=1e6+5;
int n,m,q;
struct node {
	vector<int>e;
	int d,vis;
	int f;
} v[maxn];

void f2(int gen,int xx) {
	if(xx==0) return;
	for(auto x:v[gen].e) {
		if(x!=v[gen].f) {
			v[x].f=gen;
			f2(x,xx--);
		}
	}
}

void f1(int b,int id,int dis) {
	v[id].d+=dis;
	if(b==1) {
		for(auto o:v[id].e) {
			if(v[o].f==id) {
				v[o].d+=dis;
			}
		}
	}
	if(b==2) {

		for(auto o:v[id].e) {
			v[o].d+=dis;
		}
	}
}

signed main() {
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>n;
	for(int i=1,x; i<=n; i++) {
		cin>>x;
		v[i].d=x;
	}
	for(int i=1,x,y; i<n; i++) {
		cin>>x>>y;
		v[x].e.push_back(y);
		v[y].e.push_back(x);
	}
	f2(1,n);
	cin>>m;
	for(int i=1,p,x,y; i<=m; i++) {
		cin>>p>>x>>y;
		f1(p,x,y);
	}
	cin>>q;
	for(int i=1,s; i<=q; i++) {
		cin>>s;
		cout<<v[s].d<<endl;
	}
	return 0;
}

2025/7/28 09:40
加载中...