結果

問題 No.768 Tapris and Noel play the game on Treeone
ユーザー akun0716akun0716
提出日時 2020-05-10 20:38:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 173 ms / 2,000 ms
コード長 2,238 bytes
コンパイル時間 789 ms
コンパイル使用メモリ 87,476 KB
実行使用メモリ 11,292 KB
最終ジャッジ日時 2023-09-22 15:01:45
合計ジャッジ時間 5,784 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 62 ms
7,772 KB
testcase_08 AC 32 ms
5,548 KB
testcase_09 AC 38 ms
6,128 KB
testcase_10 AC 29 ms
5,588 KB
testcase_11 AC 100 ms
10,268 KB
testcase_12 AC 102 ms
10,464 KB
testcase_13 AC 99 ms
10,276 KB
testcase_14 AC 96 ms
10,120 KB
testcase_15 AC 105 ms
10,580 KB
testcase_16 AC 104 ms
10,668 KB
testcase_17 AC 108 ms
10,696 KB
testcase_18 AC 173 ms
11,292 KB
testcase_19 AC 168 ms
11,112 KB
testcase_20 AC 165 ms
10,868 KB
testcase_21 AC 158 ms
10,232 KB
20evil_special_uni1.txt AC 121 ms
10,776 KB
20evil_special_uni2.txt AC 115 ms
10,304 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//priority_queue<int,vector<int>, greater<int> > q2;

int N;
vector<VI>G;
bool dp[200010];
bool ans[200010];
int cnt[200010];

bool dfs(int now, int pa) {
	dp[now] = true;
	
	fore(to, G[now]) {
		if (to == pa)continue;
		if (dfs(to, now)) {
			dp[now] = false;
			cnt[now]++;
		}
	}
	return dp[now];
}

void dfs1(int now, int pa) {
	//cout << now << " " << pa << endl;
	ans[now] = 1;
	fore(to, G[now])if (dp[to])ans[now] = false;
	VI wins;
	fore(to, G[now])if (dp[to]) {
		//cout << now << " " << to << endl;
		wins.push_back(to);
	}

	if (wins.size() == 0) {
		dp[now] = 1;
		fore(to, G[now])if (to != pa)dfs1(to, now);
		return;
	}
	else if (1 < wins.size()) {
		dp[now] = 0;
		fore(to, G[now])if (to != pa)dfs1(to, now);
		return;
	}
	else {
		fore(to, G[now])if (to != pa) {
			if (wins[0] == to)dp[now] = 1;
			else dp[now] = 0;
			dfs1(to, now);
		}
		return;
	}
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> N;
	G.resize(N);
	REP(i, N - 1) {
		int a, b; cin >> a >> b; a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	dfs(0,-1);
	dfs1(0, -1);
	VI a;
	REP(i, N) {
		if (ans[i])a.push_back(i + 1);
	}
	
	cout << a.size() << endl;
	REP(i, a.size())cout << a[i] << endl;

	return 0;
}

0