結果
問題 | No.768 Tapris and Noel play the game on Treeone |
ユーザー |
|
提出日時 | 2019-05-06 23:00:09 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 226 ms / 2,000 ms |
コード長 | 1,310 bytes |
コンパイル時間 | 1,960 ms |
コンパイル使用メモリ | 184,208 KB |
実行使用メモリ | 35,600 KB |
最終ジャッジ日時 | 2024-06-28 13:31:33 |
合計ジャッジ時間 | 12,652 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 20 TLE * 2 |
ソースコード
#include <bits/stdc++.h>using namespace std;bool dfs(int a, int b, vector<unordered_map<int, bool>> & dp, const vector<vector<int>> & Es){if (dp[a].count(b) > 0) return dp[a][b];for (auto c : Es[b]){if (c == a) continue;if (not dfs(b, c, dp, Es)){dp[a][b] = true;return true;}}dp[a][b] = false;return false;}int main(){cin.tie(0);ios::sync_with_stdio(false);int N;cin >> N;vector<vector<int>> Es(N, vector<int>());vector<pair<int, int>> edges;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);edges.emplace_back(make_pair(a-1, b-1));edges.emplace_back(make_pair(b-1, a-1));}vector<unordered_map<int, bool>> dp(N, unordered_map<int, bool>());for (auto &ab : edges){dfs(ab.first, ab.second, dp, Es);}vector<int> ans;for (int v = 0; v < N; ++v){bool v_wins = true;for (auto u : Es[v]){if (not dp[v][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;}