結果

問題 No.768 Tapris and Noel play the game on Treeone
ユーザー polylogKpolylogK
提出日時 2018-12-15 16:06:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 173 ms / 2,000 ms
コード長 896 bytes
コンパイル時間 1,676 ms
コンパイル使用メモリ 183,964 KB
実行使用メモリ 28,364 KB
最終ジャッジ日時 2023-10-25 21:54:06
合計ジャッジ時間 5,020 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 3 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 3 ms
4,348 KB
testcase_07 AC 68 ms
18,244 KB
testcase_08 AC 31 ms
10,964 KB
testcase_09 AC 37 ms
12,548 KB
testcase_10 AC 28 ms
10,436 KB
testcase_11 AC 111 ms
26,472 KB
testcase_12 AC 119 ms
26,588 KB
testcase_13 AC 123 ms
25,952 KB
testcase_14 AC 122 ms
25,944 KB
testcase_15 AC 133 ms
27,316 KB
testcase_16 AC 134 ms
27,404 KB
testcase_17 AC 137 ms
27,836 KB
testcase_18 AC 157 ms
28,364 KB
testcase_19 AC 135 ms
28,244 KB
testcase_20 AC 173 ms
27,152 KB
testcase_21 AC 155 ms
26,092 KB
20evil_special_uni1.txt AC 163 ms
27,632 KB
20evil_special_uni2.txt AC 157 ms
26,392 KB
権限があれば一括ダウンロードができます

ソースコード

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 = 0, int par = -1, bool f = true) {
	if(dp[v].count(par)) return;
	
	int ret = 0;
	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] - !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();
	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