結果

問題 No.2618 除霊
ユーザー kwm_tkwm_t
提出日時 2024-01-28 16:25:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 429 ms / 2,000 ms
コード長 1,714 bytes
コンパイル時間 6,256 ms
コンパイル使用メモリ 206,400 KB
実行使用メモリ 17,464 KB
最終ジャッジ日時 2024-01-28 16:25:58
合計ジャッジ時間 33,393 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 379 ms
16,428 KB
testcase_07 AC 391 ms
16,396 KB
testcase_08 AC 385 ms
16,644 KB
testcase_09 AC 384 ms
16,400 KB
testcase_10 AC 400 ms
16,624 KB
testcase_11 AC 381 ms
16,528 KB
testcase_12 AC 388 ms
16,556 KB
testcase_13 AC 347 ms
17,276 KB
testcase_14 AC 360 ms
17,108 KB
testcase_15 AC 333 ms
17,016 KB
testcase_16 AC 348 ms
16,964 KB
testcase_17 AC 362 ms
17,464 KB
testcase_18 AC 365 ms
16,788 KB
testcase_19 AC 352 ms
17,348 KB
testcase_20 AC 334 ms
17,080 KB
testcase_21 AC 372 ms
16,728 KB
testcase_22 AC 368 ms
17,440 KB
testcase_23 AC 351 ms
17,332 KB
testcase_24 AC 345 ms
17,140 KB
testcase_25 AC 369 ms
17,372 KB
testcase_26 AC 362 ms
16,700 KB
testcase_27 AC 347 ms
17,052 KB
testcase_28 AC 346 ms
17,396 KB
testcase_29 AC 363 ms
17,344 KB
testcase_30 AC 381 ms
17,336 KB
testcase_31 AC 419 ms
16,708 KB
testcase_32 AC 368 ms
16,836 KB
testcase_33 AC 398 ms
16,836 KB
testcase_34 AC 372 ms
16,252 KB
testcase_35 AC 391 ms
16,588 KB
testcase_36 AC 398 ms
16,836 KB
testcase_37 AC 384 ms
16,444 KB
testcase_38 AC 429 ms
16,836 KB
testcase_39 AC 423 ms
16,836 KB
testcase_40 AC 397 ms
16,616 KB
testcase_41 AC 401 ms
16,836 KB
testcase_42 AC 413 ms
16,636 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
//using mint = modint998244353;
//const int mod = 998244353;
//using mint = modint1000000007;
//const int mod = 1000000007;
//const int INF = 1e9;
//const long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n-1); i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define P pair<int,int>
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n; cin >> n;
	vector<vector<int>>to(n);
	rep(i, n - 1) {
		int a, b; cin >> a >> b;
		a--, b--;
		to[a].push_back(b);
		to[b].push_back(a);
	}
	vector<int>g(n);
	int m; cin >> m;
	rep(i, m) {
		int v; cin >> v;
		v--;
		g[v]++;
	}
	vector<int>cnt(n);//何匹に監視されているか
	rep(i, n) {
		if (!g[i]) continue;
		cnt[i]++;
		for (auto j : to[i]) cnt[j]++;
	}
	vector<int>c1(n);//gから距離1かつそれにのみ監視されているものの個数
	rep(i, n) {
		if (!g[i]) continue;
		for (auto j : to[i]) c1[i] += (cnt[j] == 1);
	}
	int cur = 0;
	rep(i, n)if (cnt[i])cur++;
	rep(i, n) {
		int ans = cur;
		if (cnt[i])ans--;
		for (auto j : to[i]) {
			if (!cnt[j])continue;
			int val = cnt[j] - g[i] - g[j];
			if (!val)ans--;
			if (g[j]) ans -= c1[j] - (1 == cnt[i]);
		}
		cout << ans << endl;
	}
	return 0;
}
0