結果

問題 No.899 γatheree
ユーザー latte0119latte0119
提出日時 2019-10-04 23:06:45
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,729 bytes
コンパイル時間 3,243 ms
コンパイル使用メモリ 154,040 KB
実行使用メモリ 14,772 KB
最終ジャッジ日時 2023-07-26 22:05:29
合計ジャッジ時間 10,242 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

const int B=400;


int N;
vint G[111111];

int who[3][111111];
int A[111111];


int par[111111],dep[111111];
void dfs(int v,int p,int d){
	par[v]=p;
	dep[v]=d;
	for(auto u:G[v]){
		if(u==p)continue;
		dfs(u,v,d+1);
	}
}


inline bool isok(int a,int b){
	return false;
	rep(i,2){
		if(dep[a]<dep[b])swap(a,b);
		a=par[a];
		if(a==b)return true;
	}
	return false;
}
void calc(int q){
	vint x(q);
	rep(i,q)scanf("%lld",&x[i]);

	memset(who,-1,sizeof(who));
	queue<pint>que;
	rep(i,q){
		if(who[x[i]][0]!=-1)continue;
		who[0][x[i]]=i;
		que.push(pint(0,x[i]));	
	}
	while(que.size()){
		int d,v;
		tie(d,v)=que.front();
		que.pop();
		if(d==2)continue;
		for(auto u:G[v]){
			if(who[d+1][u]!=-1)continue;
			who[d+1][u]=who[d][v];
			que.push(pint(d+1,u));
		}
	}
	rep(i,N){
		int k=10;
		rep(j,3)if(who[j][i]!=-1)chmin(k,who[j][i]);
		if(k==10)continue;
		if(x[k]==i)continue;
		A[x[k]]+=A[i];
		A[i]=0;
	}


	rep(i,q){
		for(int j=0;j<i;j++){
			if(x[j]!=x[i]&&isok(x[j],x[i])){
				A[x[i]]+=A[x[j]];
				A[x[j]]=0;
			}
		}
		printf("%lld\n",A[x[i]]);
	}
}

signed main(){
	scanf("%lld",&N);
	rep(i,N-1){
		int a,b;
		scanf("%lld%lld",&a,&b);
		G[a].pb(b);G[b].pb(a);
	}
	rep(i,N)scanf("%lld",&A[i]);

	dfs(0,-1,0);

	int Q;scanf("%lld",&Q);

	for(int i=0;i<Q;i+=B){
		calc(min(Q-i,B));
	}
	return 0;
}
0