0分但样例过了,求助
查看原帖
0分但样例过了,求助
1295609
twj__Anno楼主2025/7/28 09:51

虽然是暴力但为什么一个点都过不了QAQ

#include<bits/stdc++.h>
using namespace std;
const int maxn=1e6+5;
struct node {
	vector<int>s;
	int f;
	long long num;
} v[maxn];
int n,m,q;

void T1(int x,int y) {
	v[x].num+=y;
	if(v[x].s.empty()) return;
	for(int i:v[x].s) {
		T1(i,y);
	}
}

void T2(int x,int y) {
	v[x].num+=y;
	v[v[x].f].num+=y;
	for(int i:v[x].s) {
		v[i].num+=y;
	}
}

int main() {
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>n;
	for(int i=1; i<=n; i++) cin>>v[i].num;
	for(int i=1,x,y; i<n; i++) cin>>x>>y,v[x].s.push_back(y),v[y].f=x;
	cin>>m;
	for(int i=1,t,d,z; i<=m; i++) {
		cin>>t>>d>>z;
		if(t==1) T1(d,z);
		else T2(d,z);
	}
	cin>>q;
	for(int i=1,x; i<=q; i++) cin>>x,cout<<v[x].num<<'\n';
	return 0;
}
2025/7/28 09:51
加载中...