結果

問題 No.2618 除霊
ユーザー inksamuraiinksamurai
提出日時 2024-01-27 03:34:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 139 ms / 2,000 ms
コード長 1,470 bytes
コンパイル時間 2,766 ms
コンパイル使用メモリ 207,668 KB
実行使用メモリ 18,240 KB
最終ジャッジ日時 2024-01-27 03:34:48
合計ジャッジ時間 11,095 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 117 ms
17,196 KB
testcase_07 AC 112 ms
17,036 KB
testcase_08 AC 126 ms
17,412 KB
testcase_09 AC 119 ms
17,040 KB
testcase_10 AC 131 ms
17,392 KB
testcase_11 AC 100 ms
17,296 KB
testcase_12 AC 124 ms
17,324 KB
testcase_13 AC 86 ms
18,044 KB
testcase_14 AC 110 ms
17,876 KB
testcase_15 AC 82 ms
17,784 KB
testcase_16 AC 90 ms
17,732 KB
testcase_17 AC 108 ms
18,232 KB
testcase_18 AC 108 ms
17,556 KB
testcase_19 AC 95 ms
18,116 KB
testcase_20 AC 84 ms
17,848 KB
testcase_21 AC 98 ms
17,496 KB
testcase_22 AC 107 ms
18,208 KB
testcase_23 AC 95 ms
18,228 KB
testcase_24 AC 91 ms
17,908 KB
testcase_25 AC 104 ms
18,140 KB
testcase_26 AC 105 ms
17,468 KB
testcase_27 AC 88 ms
17,820 KB
testcase_28 AC 89 ms
18,164 KB
testcase_29 AC 109 ms
18,240 KB
testcase_30 AC 113 ms
18,104 KB
testcase_31 AC 132 ms
17,476 KB
testcase_32 AC 106 ms
17,604 KB
testcase_33 AC 115 ms
17,604 KB
testcase_34 AC 109 ms
17,020 KB
testcase_35 AC 120 ms
17,356 KB
testcase_36 AC 127 ms
17,604 KB
testcase_37 AC 135 ms
17,212 KB
testcase_38 AC 139 ms
17,604 KB
testcase_39 AC 134 ms
17,604 KB
testcase_40 AC 125 ms
17,384 KB
testcase_41 AC 138 ms
17,604 KB
testcase_42 AC 132 ms
17,404 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define rng(i,c,n) for(int i=c;i<n;i++)
#define fi first
#define se second
#define pb push_back
#define all(a) a.begin(), a.end()
#define sz(a) ((int) a.size())
#define vec(...) vector<__VA_ARGS__>
#define _3PawRSC ios::sync_with_stdio(0),cin.tie(0)
typedef long long ll;
using vi=vector<int>;
using pii=pair<int,int>;
void print(){cout<<'\n';}
template<class h,class...t>
void print(const h&v,const t&...u){cout<<v<<' ',print(u...);}

void slv(){
	int n;
	cin>>n;
	vec(vi) adj(n);
	rep(i,n-1){
		int u,v;
		cin>>u>>v;
		u-=1,v-=1;
		adj[u].pb(v),adj[v].pb(u);
	}
	vi f(n);
	int k;
	cin>>k;
	rep(i,k){
		int v;
		cin>>v;
		v-=1;
		f[v]=1;
	}
	vi qs(n);
	rep(v,n){
		qs[v]+=f[v];
		for(auto u:adj[v]){
			qs[v]+=f[u];
		}
	}
	vi g(n);
	rep(v,n){
		if(!f[v]) continue;
		for(auto u:adj[v]){
			if(qs[u]==1){
				g[v]+=1;
			}
		}
	}
	int full=0;
	rep(v,n){
		full+=qs[v]>0;
	}
	// print(full);
	vi pns(n);
	rep(v,n)
	{
		// int v=4;
		int now=full;
		if(!f[v]){
			now-=(qs[v]>0);
			for(auto u:adj[v]){
				if(f[u]){
					now-=g[u];
					now-=1;
					now+=(qs[u]>1);
					now+=(qs[v]==1);
				}
			}
		}else{
			now-=1;
			for(auto u:adj[v]){
				if(f[u]){
					now-=g[u];
					now-=1;
					now+=(qs[u]>2);
				}else{
					now-=1;
					now+=(qs[u]>1);
				}
			}
		}
		pns[v]=now;
	}
	rep(v,n) print(pns[v]);
}

signed main(){
_3PawRSC;
	slv();
}
0