結果

問題 No.806 木を道に
ユーザー finefine
提出日時 2019-03-22 22:36:25
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 664 bytes
コンパイル時間 1,721 ms
コンパイル使用メモリ 171,092 KB
実行使用メモリ 13,756 KB
最終ジャッジ日時 2023-10-19 09:50:59
合計ジャッジ時間 3,366 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 10 ms
4,516 KB
testcase_11 AC 9 ms
4,348 KB
testcase_12 WA -
testcase_13 AC 31 ms
6,628 KB
testcase_14 AC 43 ms
7,684 KB
testcase_15 AC 47 ms
7,948 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 11 ms
4,516 KB
testcase_20 AC 38 ms
7,420 KB
testcase_21 AC 20 ms
5,572 KB
testcase_22 AC 58 ms
8,740 KB
testcase_23 AC 57 ms
8,740 KB
testcase_24 AC 22 ms
10,324 KB
testcase_25 AC 33 ms
13,756 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

int solve(int cur, int par, vector< vector<int> >& g) {
    int res = 0;
    int cnt = 0;
    for (int nex : g[cur]) {
        if (nex == par) continue;
        res += solve(nex, cur, g);
        cnt++;
    }
    res += max(cnt - 1, 0);
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector< vector<int> > g(n);
    for (int i = 1; i < n; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    cout << max(solve(0, -1, g) - 1, 0) << endl;
    return 0;
}
0