結果

問題 No.806 木を道に
ユーザー fine
提出日時 2019-03-22 22:36:25
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 664 bytes
コンパイル時間 1,376 ms
コンパイル使用メモリ 171,604 KB
実行使用メモリ 13,824 KB
最終ジャッジ日時 2024-09-19 06:03:17
合計ジャッジ時間 2,729 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 15 WA * 12
権限があれば一括ダウンロードができます

ソースコード

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