結果

問題 No.2618 除霊
ユーザー airthsairths
提出日時 2024-01-26 22:45:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 150 ms / 2,000 ms
コード長 3,322 bytes
コンパイル時間 1,871 ms
コンパイル使用メモリ 134,232 KB
実行使用メモリ 23,384 KB
最終ジャッジ日時 2024-09-28 08:40:26
合計ジャッジ時間 9,735 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 122 ms
21,248 KB
testcase_07 AC 135 ms
21,248 KB
testcase_08 AC 142 ms
22,144 KB
testcase_09 AC 135 ms
22,016 KB
testcase_10 AC 146 ms
22,912 KB
testcase_11 AC 98 ms
21,104 KB
testcase_12 AC 130 ms
21,120 KB
testcase_13 AC 88 ms
21,768 KB
testcase_14 AC 114 ms
23,000 KB
testcase_15 AC 92 ms
21,380 KB
testcase_16 AC 90 ms
21,460 KB
testcase_17 AC 120 ms
22,604 KB
testcase_18 AC 129 ms
22,560 KB
testcase_19 AC 109 ms
22,116 KB
testcase_20 AC 92 ms
21,580 KB
testcase_21 AC 108 ms
21,616 KB
testcase_22 AC 115 ms
23,348 KB
testcase_23 AC 105 ms
21,960 KB
testcase_24 AC 105 ms
21,644 KB
testcase_25 AC 113 ms
22,656 KB
testcase_26 AC 114 ms
22,472 KB
testcase_27 AC 103 ms
21,564 KB
testcase_28 AC 92 ms
21,900 KB
testcase_29 AC 109 ms
22,756 KB
testcase_30 AC 119 ms
23,384 KB
testcase_31 AC 133 ms
21,376 KB
testcase_32 AC 111 ms
21,632 KB
testcase_33 AC 129 ms
21,760 KB
testcase_34 AC 118 ms
21,120 KB
testcase_35 AC 136 ms
21,632 KB
testcase_36 AC 142 ms
22,144 KB
testcase_37 AC 137 ms
21,888 KB
testcase_38 AC 150 ms
22,528 KB
testcase_39 AC 149 ms
22,784 KB
testcase_40 AC 140 ms
22,400 KB
testcase_41 AC 139 ms
23,040 KB
testcase_42 AC 141 ms
22,912 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/*
 * 
 * 	^v^
 * 
 */
#include <iostream>
#include <numeric>
#include <set>
#include <iomanip>
#include <chrono>
#include <queue>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <bitset>
#include <algorithm>
#include <array>
#include <random>

using namespace std;

using ll = long long int;
using ld = long double;

#define iamtefu ios_base::sync_with_stdio(false); cin.tie(0);
#define fl(i,a,n) for (ll i{a}; i<n; i++)
#define fr(x,s) for(auto x:s)
#define rfl(i,a,n) for (ll i{n-1}; i>=a; i--)
#define ty int _; for(cin>>_; _--;)
#define print(a) for(auto ele:a){cout<<ele<<" ";}cout<<'\n';
#define all(x) x.begin(), x.end()

template <typename L, typename R>
inline bool chmax(L &a, R b){if (a<b){a=b;return 1;}return 0;}
template <typename L, typename R>
inline bool chmin(L &a, R b){if (a>b){a=b;return 1;}return 0;}

template <typename L, typename R>
ostream& operator<<(ostream &fout, const pair<L, R> &p){
	fout<<"{"<<p.first<<","<<p.second<<"}";
	return fout;
}

template <typename L, typename R, typename U>
ostream& operator<<(ostream &fout, const tuple<L, R, U> &p){
	auto &[l, r, u] = p;
	fout<<"{"<<l<<","<<r<<","<<u<<"}";
	return fout;
}

template <typename T>
ostream& operator<<(ostream &fout, const vector <T> &v){
	for (auto &x:v){
		fout<<x<<" ";
	}
	fout<<"\n";
	return fout;
}

template <typename T>
ostream& operator<<(ostream &fout, const set <T> &st){
	for (auto &x:st){
		fout<<x<<" ";
	}
	fout<<"\n";
	return fout;
}

template <typename T>
ostream& operator<<(ostream &fout, const multiset <T> &st){
	for (auto &x:st){
		fout<<x<<" ";
	}
	fout<<"\n";
	return fout;
}

template <typename K, typename V>
ostream& operator<<(ostream &fout, const map<K, V> &mp){
	fout<<"[";
	for (auto &[x,y]:mp){
		fout<<x<<":"<<y<<" ";
	}
	fout<<"]\n";
	return fout;
}

ll gcd(ll a, ll b){
	if (b==0){
		return a;
	}
	return gcd(b, a%b);
}

mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

ll pw(ll a, ll b, ll m){
	ll res=1;
	a%=m;
	while (b){
		if (b&1){
			res=(res*a)%m;
		}
		a=(a*a)%m;
		b/=2;
	}
	return res;
}

void scn(){
	// not necessarily distinct
	// right down
	
	ll n; cin>>n;
	vector <vector <ll>> ed(n+1);
	fl(i,0,n-1){
		ll u, v; cin>>u>>v;
		ed[u].push_back(v);
		ed[v].push_back(u);
	}
	ll m; cin>>m;
	vector <ll> gd(m);
	vector <ll> tot(n+1);
	vector <ll> sin(n+1);
	vector <ll> isg(n+1);
	fl(i,0,m){
		cin>>gd[i];
		isg[gd[i]]++;
		tot[gd[i]]++;
		for (auto &x:ed[gd[i]]){
			tot[x]++;
		}
	}
	vector <ll> ser(n+1);
	fl(i,0,m){
		ser[gd[i]]+=(tot[gd[i]]==1);
		for (auto &x:ed[gd[i]]){
			ser[gd[i]]+=(tot[x]==1);
		}
	}
	ll co = 0;
	for (auto &x:tot){
		co+=(!!x);
	}
	fl(i,1,n+1){
		ll ans = max(0ll, ser[i]-(tot[i]==1));
		for (auto &x:ed[i]){
			if (isg[x]){
				ans+=(ser[x]-(tot[i]==1));
				if (tot[x]==2 && isg[i]){
					ans++;
				}
			}
		}
		cout<<co-(ans+(!!tot[i]));
		if (i!=n){
			cout<<'\n';
		}
	}
}

int main(){
	iamtefu;
#if defined(airths)
	auto t1=chrono::high_resolution_clock::now();
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	// ty
	{
		scn();
	}
#if defined(airths)
	auto t2=chrono::high_resolution_clock::now();
	ld ti=chrono::duration_cast<chrono::nanoseconds>(t2-t1).count();
	ti*=1e-6;
	cerr<<"Time: "<<setprecision(12)<<ti;
	cerr<<"ms\n";
#endif
	return 0;
}
0