結果

問題 No.768 Tapris and Noel play the game on Treeone
ユーザー polylogKpolylogK
提出日時 2018-12-15 15:40:58
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 909 bytes
コンパイル時間 5,118 ms
コンパイル使用メモリ 183,272 KB
実行使用メモリ 27,788 KB
最終ジャッジ日時 2023-10-25 21:53:12
合計ジャッジ時間 6,452 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
20evil_special_uni1.txt WA -
20evil_special_uni2.txt WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

int n;
std::vector<std::vector<int>> g;
std::vector<std::map<int, int>> dp;
void dfs(int v, int par = -1, bool f = true) {
	if(dp[v].count(par)) return;
	
	bool ret = false;
	if(f || par == -1) {
		for(auto e : g[v]) {
			if(e == par) continue;
			dfs(e, v, f);
			ret |= !dp[e][v];
		}
	} else {
		dfs(v, -1, f);
		dfs(par, v, f);
		ret = !(dp[v][-1] and dp[par][v]);
	}
	dp[v][par] = ret;
	return;
}

int main() {
	scanf("%d", &n); g.resize(n); dp.resize(n);
	for(int i = 0; i < n - 1; i++) {
		int a, b; scanf("%d%d", &a, &b);
		
		g[a - 1].push_back(b - 1);
		g[b - 1].push_back(a - 1);
	}
	
	dfs(0, -1, true);
	std::vector<int> ans;
	for(int i = 0; i < n; i++) {
		dfs(i, -1, false);
		if(dp[i][-1]) ans.push_back(i + 1);
	}
	printf("%d\n", ans.size());
	for(auto v : ans) printf("%d\n", v);
	return 0;
}
0