結果

問題 No.2618 除霊
ユーザー Carpenters-CatCarpenters-Cat
提出日時 2024-01-27 03:12:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 580 ms / 2,000 ms
コード長 956 bytes
コンパイル時間 2,676 ms
コンパイル使用メモリ 205,232 KB
実行使用メモリ 18,212 KB
最終ジャッジ日時 2024-01-27 03:13:21
合計ジャッジ時間 25,492 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
8,092 KB
testcase_01 AC 4 ms
8,092 KB
testcase_02 AC 4 ms
8,092 KB
testcase_03 AC 4 ms
8,092 KB
testcase_04 AC 5 ms
8,092 KB
testcase_05 AC 4 ms
8,092 KB
testcase_06 AC 491 ms
17,308 KB
testcase_07 AC 516 ms
17,308 KB
testcase_08 AC 497 ms
17,436 KB
testcase_09 AC 546 ms
17,308 KB
testcase_10 AC 538 ms
17,436 KB
testcase_11 AC 498 ms
17,464 KB
testcase_12 AC 515 ms
17,308 KB
testcase_13 AC 442 ms
18,076 KB
testcase_14 AC 542 ms
17,944 KB
testcase_15 AC 427 ms
17,900 KB
testcase_16 AC 435 ms
17,852 KB
testcase_17 AC 532 ms
18,204 KB
testcase_18 AC 501 ms
17,728 KB
testcase_19 AC 451 ms
18,088 KB
testcase_20 AC 430 ms
17,924 KB
testcase_21 AC 488 ms
17,696 KB
testcase_22 AC 512 ms
18,180 KB
testcase_23 AC 443 ms
18,200 KB
testcase_24 AC 446 ms
17,956 KB
testcase_25 AC 526 ms
18,112 KB
testcase_26 AC 488 ms
17,664 KB
testcase_27 AC 441 ms
17,892 KB
testcase_28 AC 441 ms
18,136 KB
testcase_29 AC 519 ms
18,212 KB
testcase_30 AC 536 ms
18,076 KB
testcase_31 AC 525 ms
17,436 KB
testcase_32 AC 497 ms
17,692 KB
testcase_33 AC 474 ms
17,692 KB
testcase_34 AC 461 ms
17,180 KB
testcase_35 AC 489 ms
17,436 KB
testcase_36 AC 527 ms
17,692 KB
testcase_37 AC 512 ms
17,308 KB
testcase_38 AC 534 ms
17,692 KB
testcase_39 AC 532 ms
17,692 KB
testcase_40 AC 536 ms
17,436 KB
testcase_41 AC 561 ms
17,692 KB
testcase_42 AC 580 ms
17,436 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main () {
	int N;
	cin >> N;
	std::vector<int> tr[200020] ;
	for (int i = 1; i < N; i ++) {
		int a, b;
		cin >> a >> b;
		tr[--a].push_back(--b);
		tr[b].push_back(a);
	}
	vector<int> ex(N, 0);
	vector<int> ne_h(N, 0);
	int M;
	cin >> M;
	for (int i = 0; i < M; i ++) {
		int a;
		cin >> a;
		ex[--a] = 1;
		for (auto v : tr[a]) {
			ne_h[v] = 1;
		}
		ne_h[a] = 1;
	}
	int sssu = accumulate(ne_h.begin(), ne_h.end(), 0);
	vector<int> ans(N, sssu), adj(N, 0);
	for (int i = 0; i < N; i ++) {
		if (!ne_h[i]) continue;
		ans[i] --;
		int fl = -1;
		for (auto v : tr[i]) {
			if (ex[v]) {
				if (fl != -1) {
					fl = -2;
				} else {
					fl = v;
				}
			}
		}
		if (fl >= 0) {
			ans[fl] --;
			if (!ex[i]) {
				adj[fl] --;
				ans[i] ++;
			}
		} else if (fl == -1) {
			adj[i] --;
		}
	}
	for (int i = 0; i < N; i ++) {
		for (auto v : tr[i]) {
			ans[i] += adj[v];
		}
		cout << ans[i] << endl;
	}
}
0