結果
問題 |
No.768 Tapris and Noel play the game on Treeone
|
ユーザー |
|
提出日時 | 2019-05-06 23:21:53 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 201 ms / 2,000 ms |
コード長 | 1,163 bytes |
コンパイル時間 | 1,745 ms |
コンパイル使用メモリ | 181,868 KB |
実行使用メモリ | 20,832 KB |
最終ジャッジ日時 | 2024-06-28 13:53:24 |
合計ジャッジ時間 | 11,140 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 20 TLE * 2 |
ソースコード
#include <bits/stdc++.h> using namespace std; constexpr long long shift = 1LL<<32; unordered_map<long long, bool> dp; vector<vector<int>> Es(100000, vector<int>()); bool dfs(int a, int b){ long long ab = a * shift + b; if (dp.count(ab) > 0) return dp[ab]; for (auto c : Es[b]){ if (c == a) continue; if (not dfs(b, c)){ dp[ab] = true; return true; } } dp[ab] = false; return false; } int main(){ cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; for (int i = 1; i < N; ++i){ int a, b; cin >> a >> b; Es[a-1].push_back(b-1); Es[b-1].push_back(a-1); } for (int a = 0; a < N; ++a){ for (auto b : Es[a]){ dfs(a, b); } } vector<int> ans; for (int v = 0; v < N; ++v){ bool v_wins = true; for (auto u : Es[v]){ if (not dp[v * shift + u]){ v_wins = false; break; } } if (v_wins) ans.push_back(v + 1); } cout << ans.size() << '\n'; for (auto v : ans) cout << v << '\n'; return 0; }