結果

問題 No.768 Tapris and Noel play the game on Treeone
ユーザー sugim48sugim48
提出日時 2018-12-19 01:56:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 54 ms / 2,000 ms
コード長 1,265 bytes
コンパイル時間 2,038 ms
コンパイル使用メモリ 207,828 KB
実行使用メモリ 9,992 KB
最終ジャッジ日時 2023-10-25 23:48:48
合計ジャッジ時間 3,958 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 32 ms
7,084 KB
testcase_08 AC 17 ms
5,440 KB
testcase_09 AC 20 ms
5,800 KB
testcase_10 AC 15 ms
5,288 KB
testcase_11 AC 51 ms
9,024 KB
testcase_12 AC 52 ms
9,160 KB
testcase_13 AC 49 ms
8,904 KB
testcase_14 AC 50 ms
8,884 KB
testcase_15 AC 53 ms
9,212 KB
testcase_16 AC 54 ms
9,236 KB
testcase_17 AC 54 ms
9,348 KB
testcase_18 AC 45 ms
9,992 KB
testcase_19 AC 45 ms
9,904 KB
testcase_20 AC 48 ms
9,788 KB
testcase_21 AC 45 ms
9,416 KB
20evil_special_uni1.txt AC 52 ms
9,424 KB
20evil_special_uni2.txt AC 51 ms
9,100 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define rep(i, N) for (int i = 0; i < (N); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back

using ll = long long;
using i_i = tuple<int, int>;

void dfs_down(int u, int p, vector<vector<int>>& G, vector<bool>& down) {
    down[u] = true;
    for (int v: G[u]) if (v != p) {
        dfs_down(v, u, G, down);
        if (down[v]) down[u] = false;
    }
}

void dfs_up(int u, int p, vector<vector<int>>& G, vector<bool>& down, vector<bool>& up) {
    int cnt = up[u];
    for (int v: G[u]) if (v != p) cnt += down[v];
    for (int v: G[u]) if (v != p) {
        up[v] = (cnt - down[v] == 0);
        dfs_up(v, u, G, down, up);
    }
}

int main() {
    int N; cin >> N;
    vector<vector<int>> G(N);
    rep(i, N - 1) {
        int u, v;
        scanf("%d%d", &u, &v);
        u--; v--;
        G[u].pb(v);
        G[v].pb(u);
    }
    vector<bool> down(N);
    dfs_down(0, -1, G, down);
    vector<bool> up(N);
    dfs_up(0, -1, G, down, up);
    vector<int> V;
    rep(u, N) if (down[u] && !up[u]) V.pb(u);
    int M = V.size();
    cout << M << endl;
    rep(j, M) printf("%d\n", V[j] + 1);
    // rep(u, N) cout << down[u];
    // cout << endl;
    // rep(u, N) cout << up[u];
    // cout << endl;
}
0