結果

問題 No.768 Tapris and Noel play the game on Treeone
ユーザー chocorusk
提出日時 2018-12-16 01:48:35
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,372 bytes
コンパイル時間 961 ms
コンパイル使用メモリ 99,412 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-09-25 06:21:13
合計ジャッジ時間 4,127 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 2 WA * 20
権限があれば一括ダウンロードができます

ソースコード

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 noel[100000];
bool used[100000];
int dp[100000];
int p[100000];
void dfs(int x){
	used[x]=1;
	if(noel[x]) dp[x]++;
	else dp[x]--;
	for(auto y:g[x]){
		if(used[y]){
			p[x]=y;
			continue;
		}
		if(noel[x]) noel[y]=0;
		else noel[y]=1;
		dfs(y);
		dp[x]+=dp[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);
	}
	noel[0]=1;
	dfs(0);
	vector<int> ans;
	for(int x=0; x<n; x++){
		if(noel[x]){
			bool nuee=0;
			for(auto y:g[x]){
				if(p[x]==y) continue;
				if(dp[y]<0){
					nuee=1;
					break;
				}
			}
			if(dp[0]-dp[x]<0) nuee=1;
			if(!nuee) ans.push_back(x);
		}else{
			bool nuee=0;
			for(auto y:g[x]){
				if(p[x]==y) continue;
				if(dp[y]>0){
					nuee=1;
					break;
				}
			}
			if(dp[0]-dp[x]>0) nuee=1;
			if(!nuee) ans.push_back(x);
		}
	}
	cout<<ans.size()<<endl;
	for(int i=0; i<ans.size(); i++){
		cout<<ans[i]+1<<endl;
	}
	return 0;
}
0