結果

問題 No.768 Tapris and Noel play the game on Treeone
ユーザー chocoruskchocorusk
提出日時 2018-12-16 04:07:56
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,116 bytes
コンパイル時間 1,021 ms
コンパイル使用メモリ 97,824 KB
実行使用メモリ 9,976 KB
最終ジャッジ日時 2023-10-25 22:06:30
合計ジャッジ時間 3,996 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,788 KB
testcase_01 AC 2 ms
5,788 KB
testcase_02 AC 2 ms
5,788 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 <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 w[100000];
int wct[100000];
bool wp[100000];
bool used[100000];
void dfs(int x){
	used[x]=1;
	w[x]=1;
	for(auto y:g[x]){
		if(used[y]) continue;
		dfs(y);
		if(w[y]){
			w[x]=0;
			wct[x]++;
		}
	}
}
vector<int> ans;
void dfs2(int x){
	used[x]=1;
	int ct0=wct[x];
	if(wp[x]) ct0++;
	if(ct0==0) ans.push_back(x);
	for(auto y:g[x]){
		if(used[y]) continue;
		int ct=wct[x];
		if(w[y]) ct--;
		if(wp[x]) ct++;
		if(ct==0) wp[y]=1;
		dfs2(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);
	}
	dfs(0);
	fill(used, used+n, 0);
	dfs2(0);
	cout<<ans.size()<<endl;
	for(auto x:ans) cout<<x+1<<endl;
	return 0;
}
0