結果

問題 No.768 Tapris and Noel play the game on Treeone
ユーザー chocorusk
提出日時 2018-12-16 04:21:25
言語 C++11
(gcc 13.3.0)
結果
AC  
実行時間 214 ms / 2,000 ms
コード長 1,147 bytes
コンパイル時間 954 ms
コンパイル使用メモリ 100,588 KB
実行使用メモリ 10,180 KB
最終ジャッジ日時 2024-09-25 06:25:51
合計ジャッジ時間 4,446 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#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;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0