結果

問題 No.2618 除霊
ユーザー Carpenters-CatCarpenters-Cat
提出日時 2024-01-27 02:58:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 887 bytes
コンパイル時間 2,554 ms
コンパイル使用メモリ 205,236 KB
実行使用メモリ 25,528 KB
最終ジャッジ日時 2024-01-27 02:59:03
合計ジャッジ時間 11,876 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 5 ms
8,220 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 558 ms
16,668 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
権限があれば一括ダウンロードができます

ソースコード

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);
	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]) {
				for (auto v : tr[fl]) {
					if (v != i) {
						ans[v] --;
					}
				}
			}
		}
	}
	for (auto a : ans) {
		cout << a << endl;
	}
}
0