結果

問題 No.768 Tapris and Noel play the game on Treeone
ユーザー polylogKpolylogK
提出日時 2019-09-10 18:01:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 202 ms / 2,000 ms
コード長 1,238 bytes
コンパイル時間 1,776 ms
コンパイル使用メモリ 180,952 KB
実行使用メモリ 32,548 KB
最終ジャッジ日時 2023-09-15 13:06:09
合計ジャッジ時間 5,655 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 3 ms
4,384 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 87 ms
18,916 KB
testcase_08 AC 36 ms
11,176 KB
testcase_09 AC 45 ms
12,808 KB
testcase_10 AC 34 ms
10,420 KB
testcase_11 AC 162 ms
27,564 KB
testcase_12 AC 163 ms
27,848 KB
testcase_13 AC 148 ms
27,020 KB
testcase_14 AC 145 ms
26,976 KB
testcase_15 AC 158 ms
28,508 KB
testcase_16 AC 153 ms
28,568 KB
testcase_17 AC 169 ms
29,144 KB
testcase_18 AC 182 ms
32,548 KB
testcase_19 AC 171 ms
32,308 KB
testcase_20 AC 202 ms
31,168 KB
testcase_21 AC 188 ms
29,812 KB
20evil_special_uni1.txt AC 200 ms
29,660 KB
20evil_special_uni2.txt AC 187 ms
28,232 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int n; scanf("%d", &n);
	std::vector<std::vector<int>> g(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<std::map<int, int>> dp(n);
	auto solve = [&](auto&& solve, int v, int par, bool flag) -> int {
		if(dp[v].count(par)) return dp[v][par];
			
		int val = 0;
		if(flag or par == -1) {
			for(auto e: g[v]) {
				if(e == par) continue;
				val += !solve(solve, e, v, flag);
			}
		} else {
			int parent_val = !solve(solve, par, v, flag);
			int around_val = solve(solve, v, -1, flag);
			val = around_val - parent_val;
		}

		return dp[v][par] = val;
	};
	solve(solve, 0, -1, 1);

	std::set<int> st;
	for(int v = 0; v < n; v++) if(!solve(solve, v, -1, 0)) st.insert(v);

	printf("%d\n", st.size());
	for(auto v: st) printf("%d\n", v + 1);
	return 0;
}
0