結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,776 KB
testcase_01 AC 2 ms
5,776 KB
testcase_02 AC 2 ms
5,776 KB
testcase_03 AC 3 ms
5,812 KB
testcase_04 AC 3 ms
5,816 KB
testcase_05 AC 3 ms
5,808 KB
testcase_06 AC 3 ms
5,800 KB
testcase_07 AC 82 ms
8,264 KB
testcase_08 AC 43 ms
7,116 KB
testcase_09 AC 51 ms
7,368 KB
testcase_10 AC 38 ms
7,008 KB
testcase_11 AC 128 ms
9,556 KB
testcase_12 AC 129 ms
9,576 KB
testcase_13 AC 124 ms
9,484 KB
testcase_14 AC 124 ms
9,464 KB
testcase_15 AC 132 ms
9,676 KB
testcase_16 AC 133 ms
9,696 KB
testcase_17 AC 136 ms
9,772 KB
testcase_18 AC 220 ms
9,896 KB
testcase_19 AC 220 ms
9,756 KB
testcase_20 AC 216 ms
9,936 KB
testcase_21 AC 201 ms
9,632 KB
20evil_special_uni1.txt AC 167 ms
9,888 KB
20evil_special_uni2.txt AC 155 ms
9,672 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