結果

問題 No.768 Tapris and Noel play the game on Treeone
ユーザー ahe100ahe100
提出日時 2019-01-10 06:36:03
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,681 bytes
コンパイル時間 655 ms
コンパイル使用メモリ 76,932 KB
実行使用メモリ 17,396 KB
最終ジャッジ日時 2024-05-03 03:59:04
合計ジャッジ時間 3,570 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 3 ms
8,192 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
20evil_special_uni1.txt WA -
20evil_special_uni2.txt WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;
ll mod = 1e9+7;
//LLONG_MIN

/*
グラフに必敗に繋がる辺の数をメモしておくと計算量短縮
grundyは0か非0かだけが意味を持つ
相手に0を押し付ければ勝てる
*/

ll n,lose[100010]={},visit[100010]={};
vector<ll> v[100010],grundy[100010],ans;

ll dfs(ll par,ll p,ll edge_id){
	if(par!=-1){
		if(grundy[par][edge_id]!=-1 && lose[p]-grundy[par][edge_id]>0)return 1;//1手で0に行けるので
		if(visit[p]==v[p].size())return 0;//全部の点を探索し終えた上で勝ち筋が無かったらアウト
	}else{
		if(lose[p]>0)return 1;//1手で0に行けるので
		if(visit[p]==v[p].size())return 0;//
	}
	ll lose_num=0;
	rep(i,v[p].size()){
		if(v[p][i]==par)continue;
		if(grundy[p][i]==-1){
			grundy[p][i]=dfs(p,v[p][i],i);
			if(grundy[p][i]==0)lose[p]++;
			visit[p]++;
		}
		if(grundy[p][i]==0)lose_num=1;
	}
	return lose_num;
}

int main(void){
	cin>>n;
	rep(i,n-1){
		ll a,b;
		cin>>a>>b;
		v[a].push_back(b);
		v[b].push_back(a);
		grundy[a].push_back(-1);
		grundy[b].push_back(-1);
	}
	reg(i,1,n){
		if(dfs(-1,i,0)==0)ans.push_back(i);
	}
	cout<<ans.size()<<endl;
	rep(i,ans.size())cout<<ans[i]<<endl;
	return 0;
}
0