結果

問題 No.768 Tapris and Noel play the game on Treeone
ユーザー ahe100ahe100
提出日時 2019-01-10 06:30:53
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,496 bytes
コンパイル時間 910 ms
コンパイル使用メモリ 77,072 KB
実行使用メモリ 16,580 KB
最終ジャッジ日時 2024-05-03 03:58:59
合計ジャッジ時間 7,341 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
15,196 KB
testcase_01 AC 2 ms
8,084 KB
testcase_02 AC 3 ms
8,008 KB
testcase_03 AC 3 ms
8,260 KB
testcase_04 AC 5 ms
8,088 KB
testcase_05 AC 4 ms
8,212 KB
testcase_06 AC 5 ms
8,256 KB
testcase_07 AC 92 ms
13,256 KB
testcase_08 AC 45 ms
10,944 KB
testcase_09 AC 58 ms
11,456 KB
testcase_10 AC 44 ms
10,692 KB
testcase_11 AC 149 ms
16,072 KB
testcase_12 AC 148 ms
16,196 KB
testcase_13 AC 160 ms
16,064 KB
testcase_14 AC 159 ms
15,812 KB
testcase_15 AC 161 ms
16,328 KB
testcase_16 AC 156 ms
16,452 KB
testcase_17 AC 158 ms
16,580 KB
testcase_18 TLE -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
20evil_special_uni1.txt -- -
20evil_special_uni2.txt -- -
権限があれば一括ダウンロードができます

ソースコード

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]={};
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に行けるので
	}else{
		if(lose[p]>0)return 1;//1手で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]++;
		}
		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