結果

問題 No.768 Tapris and Noel play the game on Treeone
ユーザー chocoruskchocorusk
提出日時 2018-12-16 01:48:35
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,372 bytes
コンパイル時間 1,278 ms
コンパイル使用メモリ 99,796 KB
実行使用メモリ 10,772 KB
最終ジャッジ日時 2023-10-25 21:58:45
合計ジャッジ時間 4,404 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,096 KB
testcase_01 AC 3 ms
6,096 KB
testcase_02 AC 2 ms
6,096 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 AC 193 ms
10,772 KB
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 <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