結果

問題 No.768 Tapris and Noel play the game on Treeone
ユーザー square1001square1001
提出日時 2019-03-27 16:41:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,146 bytes
コンパイル時間 918 ms
コンパイル使用メモリ 80,532 KB
実行使用メモリ 9,744 KB
最終ジャッジ日時 2024-04-19 10:02:36
合計ジャッジ時間 2,670 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 WA -
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 55 ms
9,744 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
20evil_special_uni1.txt WA -
20evil_special_uni2.txt WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <vector>
#include <iostream>
#include <functional>
using namespace std;
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<vector<int> > G(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);
	}
	vector<bool> dp_up(N, true), dp_down(N);
	function<void(int, int)> dfs_up = [&](int pos, int pre) {
		int cnt = 0;
		for (int i : G[pos]) {
			if (i == pre) continue;
			dfs_up(i, pos);
			if (dp_up[i]) dp_up[pos] = false;
			++cnt;
		}
	};
	dfs_up(0, -1);
	dp_down[0] = true;
	function<void(int, int)> dfs_down = [&](int pos, int pre) {
		int sum = 0;
		for (int i : G[pos]) {
			if (i == pre) continue;
			sum += (!dp_up[i] ? 1 : 0);
		}
		for (int i : G[pos]) {
			if (i == pre) continue;
			if (!dp_down[pos]) dp_down[i] = true;
			if (sum - (!dp_up[i] ? 1 : 0) == 0) dp_down[i] = true;
			dfs_down(i, pos);
		}
	};
	dfs_down(0, -1);
	vector<int> ans;
	for (int i = 0; i < N; ++i) {
		if (dp_up[i] && dp_down[i]) {
			ans.push_back(i);
		}
	}
	cout << ans.size() << '\n';
	for (int i : ans) {
		cout << i + 1 << '\n';
	}
	return 0;
}
0