結果

問題 No.763 Noelちゃんと木遊び
ユーザー finefine
提出日時 2018-12-12 19:21:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 50 ms / 2,000 ms
コード長 665 bytes
コンパイル時間 1,659 ms
コンパイル使用メモリ 172,400 KB
実行使用メモリ 14,788 KB
最終ジャッジ日時 2023-10-25 08:33:12
合計ジャッジ時間 4,373 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
14,788 KB
testcase_01 AC 14 ms
5,020 KB
testcase_02 AC 39 ms
7,396 KB
testcase_03 AC 25 ms
6,076 KB
testcase_04 AC 17 ms
5,284 KB
testcase_05 AC 24 ms
6,076 KB
testcase_06 AC 50 ms
8,452 KB
testcase_07 AC 44 ms
8,188 KB
testcase_08 AC 27 ms
6,340 KB
testcase_09 AC 16 ms
5,284 KB
testcase_10 AC 7 ms
4,348 KB
testcase_11 AC 50 ms
8,452 KB
testcase_12 AC 42 ms
7,924 KB
testcase_13 AC 41 ms
7,924 KB
testcase_14 AC 37 ms
7,396 KB
testcase_15 AC 24 ms
6,076 KB
testcase_16 AC 5 ms
4,348 KB
testcase_17 AC 25 ms
6,076 KB
testcase_18 AC 47 ms
8,452 KB
testcase_19 AC 46 ms
7,924 KB
testcase_20 AC 44 ms
7,924 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

int n;
vector< vector<int> > G;

int dfs(int cur, int par, int& cnt) {
    int res = 0;
    for (int nex : G[cur]) {
        if (nex == par) continue;
        if (dfs(nex, cur, cnt) == 0) {
            res = 1;
        }
    }
    cnt += (res == 0);
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    G.resize(n);
    for (int i = 1; i < n; i++) {
        int u, v;
        cin >> u >> v;
        u--; v--;
        G[u].push_back(v);
        G[v].push_back(u);
    }

    int ans = 0;
    dfs(0, -1, ans);
    cout << ans << endl;
    return 0;
}
0