关于山东J组补测T3
  • 板块学术版
  • 楼主Milthm
  • 当前回复14
  • 已保存回复14
  • 发布时间2023/3/8 18:01
  • 上次更新2023/10/23 22:41:16
查看原帖
关于山东J组补测T3
761125
Milthm楼主2023/3/8 18:01
#include<iostream>
#include<cstdio>
#define int long long
using namespace std;
struct tree{
	int son=0,father=0,brother=0,bing=0;
}a[1000005];
int n,m,q,x,y,p,br[1000005];
void dg(int x){
	a[x].bing+=y;
    if(a[x].brother!=0)dg(a[x].brother);
	if(a[x].son!=0)dg(a[x].son);
    return ;
}
void erzi(int x){
    a[x].bing+=y;
    if(a[x].brother!=0)erzi(a[x].brother);
}
signed main(){
	//freopen("deploy.in","r",stdin);
	//freopen("deploy.out","w",stdout);
	cin>>n;
	for(int i=1;i<=n;++i)cin>>a[i].bing;
	for(int i=1;i<n;++i){
		scanf("%lld%lld",&x,&y);
		if(br[x]==0){
			a[x].son=y;
			a[y].father=x;
			br[x]=y;
		}
		else{
			a[br[x]].brother=y;
			a[y].father=x;
			br[x]=y;
		}
	}
   // for(int i=1;i<=n;++i){
     //   cout<<a[i].brother<<" "<<a[i].father<<" "<<a[i].son<<endl;
    //}
	cin>>m;
	while(m--){
		scanf("%lld%lld%lld",&p,&x,&y);
		if(p==1){
            a[x].bing+=y;
			dg(a[x].son);
		} 
		else{
			a[a[x].father].bing+=y;
			a[x].bing+=y;
			erzi(a[x].son);
		}
	}
	cin>>q;
	while(q--){
		cin>>x;
		cout<<a[x].bing<<endl;
	}
	return 0;
}

我爆零力(悲),有没有大佬给我调一下或者给个hack数据qwq

2023/3/8 18:01
加载中...