結果

問題 No.768 Tapris and Noel play the game on Treeone
ユーザー polylogKpolylogK
提出日時 2018-12-15 14:55:33
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 798 bytes
コンパイル時間 1,953 ms
コンパイル使用メモリ 187,980 KB
実行使用メモリ 27,852 KB
最終ジャッジ日時 2023-10-25 21:51:06
合計ジャッジ時間 8,046 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
23,104 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 3 ms
4,348 KB
testcase_04 AC 3 ms
4,348 KB
testcase_05 AC 3 ms
4,348 KB
testcase_06 AC 3 ms
4,348 KB
testcase_07 AC 143 ms
18,236 KB
testcase_08 AC 59 ms
10,948 KB
testcase_09 AC 72 ms
12,532 KB
testcase_10 AC 51 ms
10,420 KB
testcase_11 AC 235 ms
26,456 KB
testcase_12 AC 238 ms
26,652 KB
testcase_13 AC 224 ms
25,964 KB
testcase_14 AC 230 ms
25,928 KB
testcase_15 AC 250 ms
27,296 KB
testcase_16 AC 246 ms
27,396 KB
testcase_17 AC 249 ms
27,852 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::vector<std::map<int, int>> dp;
void dfs(int v, int par = -1) {
	if(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); 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);
	}
	
	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