結果
| 問題 |
No.768 Tapris and Noel play the game on Treeone
|
| ユーザー |
chocorusk
|
| 提出日時 | 2018-12-16 23:44:17 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 212 ms / 2,000 ms |
| コード長 | 1,147 bytes |
| コンパイル時間 | 878 ms |
| コンパイル使用メモリ | 100,396 KB |
| 実行使用メモリ | 9,984 KB |
| 最終ジャッジ日時 | 2024-09-25 06:40:28 |
| 合計ジャッジ時間 | 4,283 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 22 |
ソースコード
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
vector<int> g[100000];
bool w[100000];
int wct[100000];
bool wp[100000];
bool used[100000];
void dfs(int x){
used[x]=1;
w[x]=1;
for(auto y:g[x]){
if(used[y]) continue;
dfs(y);
if(w[y]){
w[x]=0;
wct[x]++;
}
}
}
vector<int> ans;
void dfs2(int x){
used[x]=1;
int ct0=wct[x];
if(wp[x]) ct0++;
if(ct0==0) ans.push_back(x);
for(auto y:g[x]){
if(used[y]) continue;
int ct=wct[x];
if(w[y]) ct--;
if(wp[x]) ct++;
if(ct==0) wp[y]=1;
dfs2(y);
}
}
int main()
{
int n; cin>>n;
for(int i=0; i<n-1; i++){
int a, b;
cin>>a>>b;
a--; b--;
g[a].push_back(b);
g[b].push_back(a);
}
dfs(0);
fill(used, used+n, 0);
dfs2(0);
sort(ans.begin(), ans.end());
cout<<ans.size()<<endl;
for(auto x:ans) cout<<x+1<<endl;
return 0;
}
chocorusk