結果

問題 No.768 Tapris and Noel play the game on Treeone
ユーザー polylogKpolylogK
提出日時 2018-12-15 14:53:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 802 bytes
コンパイル時間 2,021 ms
コンパイル使用メモリ 189,376 KB
実行使用メモリ 32,536 KB
最終ジャッジ日時 2023-10-25 21:50:28
合計ジャッジ時間 12,694 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,696 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 4 ms
4,348 KB
testcase_04 AC 5 ms
4,348 KB
testcase_05 AC 4 ms
4,348 KB
testcase_06 AC 4 ms
4,348 KB
testcase_07 AC 418 ms
21,056 KB
testcase_08 AC 187 ms
12,496 KB
testcase_09 AC 228 ms
14,344 KB
testcase_10 AC 154 ms
11,704 KB
testcase_11 AC 722 ms
30,784 KB
testcase_12 AC 761 ms
31,080 KB
testcase_13 AC 718 ms
30,272 KB
testcase_14 AC 719 ms
30,184 KB
testcase_15 AC 778 ms
31,872 KB
testcase_16 AC 793 ms
31,980 KB
testcase_17 AC 793 ms
32,536 KB
testcase_18 TLE -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
20evil_special_uni1.txt -- -
20evil_special_uni2.txt -- -
権限があれば一括ダウンロードができます

ソースコード

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::map<int, std::map<int, int>> dp;
void dfs(int v, int par = -1) {
	if(dp.count(v) and dp[v].count(par)) return;
	
	std::set<int> st;
	for(auto e : g[v]) {
		if(e == par) continue;
		dfs(e, v);
		st.insert(dp[e][v]);
	}
	
	int tmp = 0;
	while(st.count(tmp)) tmp++;
	dp[v][par] = tmp;
	return;
}

int main() {
	scanf("%d", &n); g.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);
	}
	
	std::vector<int> ans;
	for(int i = 0; i < n; i++) {
		dfs(i);
		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