結果

問題 No.768 Tapris and Noel play the game on Treeone
ユーザー chocoruskchocorusk
提出日時 2018-12-16 04:21:25
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 195 ms / 2,000 ms
コード長 1,147 bytes
コンパイル時間 825 ms
コンパイル使用メモリ 102,176 KB
実行使用メモリ 9,936 KB
最終ジャッジ日時 2023-10-25 22:06:35
合計ジャッジ時間 4,369 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,788 KB
testcase_01 AC 2 ms
5,788 KB
testcase_02 AC 2 ms
5,788 KB
testcase_03 AC 3 ms
5,824 KB
testcase_04 AC 3 ms
5,828 KB
testcase_05 AC 3 ms
5,820 KB
testcase_06 AC 3 ms
5,812 KB
testcase_07 AC 78 ms
8,276 KB
testcase_08 AC 39 ms
7,128 KB
testcase_09 AC 49 ms
7,380 KB
testcase_10 AC 37 ms
7,020 KB
testcase_11 AC 129 ms
9,568 KB
testcase_12 AC 122 ms
9,588 KB
testcase_13 AC 122 ms
9,496 KB
testcase_14 AC 127 ms
9,476 KB
testcase_15 AC 130 ms
9,688 KB
testcase_16 AC 127 ms
9,708 KB
testcase_17 AC 125 ms
9,784 KB
testcase_18 AC 191 ms
9,896 KB
testcase_19 AC 195 ms
9,756 KB
testcase_20 AC 194 ms
9,936 KB
testcase_21 AC 182 ms
9,632 KB
20evil_special_uni1.txt AC 143 ms
9,900 KB
20evil_special_uni2.txt AC 133 ms
9,684 KB
権限があれば一括ダウンロードができます

ソースコード

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);
	sort(ans.begin(), ans.end());
	cout<<ans.size()<<endl;
	for(auto x:ans) cout<<x+1<<endl;
	return 0;
}
0