結果
| 問題 |
No.768 Tapris and Noel play the game on Treeone
|
| ユーザー |
|
| 提出日時 | 2019-05-06 23:07:44 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 201 ms / 2,000 ms |
| コード長 | 1,211 bytes |
| コンパイル時間 | 1,805 ms |
| コンパイル使用メモリ | 181,144 KB |
| 実行使用メモリ | 33,988 KB |
| 最終ジャッジ日時 | 2024-06-28 13:37:23 |
| 合計ジャッジ時間 | 11,299 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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>());
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);
}
vector<unordered_map<int, bool>> dp(N, unordered_map<int, bool>());
for (int a = 0; a < N; ++a){
for (auto b : Es[a]){
dfs(a, b,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;
}