結果

問題 No.768 Tapris and Noel play the game on Treeone
ユーザー veqccveqcc
提出日時 2019-02-23 14:56:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 88 ms / 2,000 ms
コード長 1,362 bytes
コンパイル時間 764 ms
コンパイル使用メモリ 95,052 KB
実行使用メモリ 10,200 KB
最終ジャッジ日時 2023-08-20 02:34:37
合計ジャッジ時間 3,779 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,792 KB
testcase_01 AC 3 ms
5,680 KB
testcase_02 AC 3 ms
5,748 KB
testcase_03 AC 4 ms
5,816 KB
testcase_04 AC 4 ms
5,732 KB
testcase_05 AC 4 ms
5,748 KB
testcase_06 AC 3 ms
6,048 KB
testcase_07 AC 52 ms
8,020 KB
testcase_08 AC 28 ms
6,936 KB
testcase_09 AC 33 ms
7,164 KB
testcase_10 AC 26 ms
6,928 KB
testcase_11 AC 81 ms
9,220 KB
testcase_12 AC 81 ms
9,376 KB
testcase_13 AC 80 ms
9,220 KB
testcase_14 AC 79 ms
9,448 KB
testcase_15 AC 88 ms
9,320 KB
testcase_16 AC 88 ms
9,428 KB
testcase_17 AC 88 ms
9,480 KB
testcase_18 AC 81 ms
10,124 KB
testcase_19 AC 81 ms
10,200 KB
testcase_20 AC 80 ms
9,888 KB
testcase_21 AC 74 ms
9,608 KB
20evil_special_uni1.txt AC 81 ms
9,580 KB
20evil_special_uni2.txt AC 78 ms
9,304 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

int n, a, b, dp[100005];
vector <int> edge[100005];

void dfs(int cur, int par) {
    for (int child : edge[cur]) {
        if (child == par) continue;
        dfs(child, cur);
        if (!dp[child]) dp[cur]++;
    }
}

void dfs2(int cur, int par, bool par_win) {
    dp[cur] = 0;
    for (int child : edge[cur]) {
        if (child == par) {
            if (par_win) dp[cur]++;
        } else {
            if (!dp[child]) dp[cur]++;
        }
    }

    for (int child : edge[cur]) {
        if (child == par) continue;
        bool next_par_win = (dp[cur] - (dp[child] == 0 ? 1 : 0)) == 0;
        dfs2(child, cur, next_par_win);
    }
}

int main() {
    cin >> n;
    for (int i = 1; i < n; i++) {
        cin >> a >> b;
        a--; b--;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }

    dfs(0, -1);
    dfs2(0, -1, false);

    vector <int> ans;
    for (int i = 0; i < n; i++) {
        if (dp[i] == 0) {
            ans.push_back(i + 1);
        }
    }

    cout << ans.size() << "\n";
    for (int ret : ans) {
        cout << ret << "\n";
    }

    return 0;
}
0