結果
| 問題 |
No.768 Tapris and Noel play the game on Treeone
|
| コンテスト | |
| ユーザー |
Taiki0715
|
| 提出日時 | 2023-05-03 17:19:42 |
| 言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 143 ms / 2,000 ms |
| コード長 | 2,075 bytes |
| コンパイル時間 | 6,341 ms |
| コンパイル使用メモリ | 162,620 KB |
| 実行使用メモリ | 9,940 KB |
| 最終ジャッジ日時 | 2024-11-21 19:39:53 |
| 合計ジャッジ時間 | 10,955 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 22 |
ソースコード
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <math.h>
#include <cassert>
#include <bitset>
#include <map>
#include <algorithm>
#include <iterator>
#include <string>
#include <utility>
#include <numeric>
#include <regex>
#include <complex>
#include <atcoder/all>
using namespace atcoder;
using namespace std;
using ll=long long;
using ull=unsigned long long;
using P=pair<ll,ll>;
template<typename T>using minque=priority_queue<T,vector<T>,greater<T>>;
template<typename T>bool chmax(T &a,const T &b){return (a<b?(a=b,true):false);}
template<typename T>bool chmin(T &a,const T &b){return (a>b?(a=b,true):false);}
template<typename T1,typename T2>
ostream &operator<<(ostream &os,const pair<T1,T2>&p){
os<<p.first<<" "<<p.second;
return os;
}
template<typename T1,typename T2>
istream &operator>>(istream &is,pair<T1,T2>&p){
is>>p.first>>p.second;
return is;
}
template<typename T>
istream &operator>>(istream &is,vector<T> &a){
for(auto &i:a)is>>i;
return is;
}
#define reps(i,a,n) for(int i=(a);i<(n);i++)
#define rep(i,n) reps(i,0,n)
#define all(x) x.begin(),x.end()
ll myceil(ll a,ll b){return (a+b-1)/b;}
int n;
vector<vector<int>>to;
vector<bool>dp,ans;
void dfs(int x,int p){
dp[x]=true;
for(auto i:to[x]){
if(i==p)continue;
dfs(i,x);
if(dp[i])dp[x]=false;
}
}
void dfs2(int x,int p){
ans[x]=true;
for(auto i:to[x])if(dp[i])ans[x]=false;
int s=to[x].size();
vector<bool>lft(s),rht(s);
rep(i,s)lft[i]=rht[i]=dp[to[x][i]];
reps(i,1,s)lft[i]=lft[i]||lft[i-1];
for(int i=s-2;i>=0;i--)rht[i]=rht[i]||rht[i+1];
rep(i,s){
if(to[x][i]==p)continue;
dp[x]=true;
if(0<i&&lft[i-1])dp[x]=false;
if(i<s-1&&rht[i+1])dp[x]=false;
dfs2(to[x][i],x);
}
}
int main(){
cin>>n;
to.resize(n);
rep(i,n-1){
int a,b;
cin>>a>>b;
a--,b--;
to[a].push_back(b);
to[b].push_back(a);
}
dp.resize(n),ans.resize(n);
dfs(0,-1);
dfs2(0,-1);
vector<int>id;
rep(i,n)if(ans[i])id.push_back(i+1);
cout<<id.size()<<'\n';
for(auto i:id)cout<<i<<'\n';
}
Taiki0715