結果

問題 No.806 木を道に
ユーザー mikianaaamikianaaa
提出日時 2020-09-10 17:20:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 37 ms / 2,000 ms
コード長 718 bytes
コンパイル時間 1,615 ms
コンパイル使用メモリ 168,932 KB
実行使用メモリ 8,848 KB
最終ジャッジ日時 2023-08-25 01:50:57
合計ジャッジ時間 3,475 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 8 ms
4,380 KB
testcase_11 AC 8 ms
4,380 KB
testcase_12 AC 30 ms
7,760 KB
testcase_13 AC 21 ms
6,384 KB
testcase_14 AC 29 ms
7,524 KB
testcase_15 AC 30 ms
7,700 KB
testcase_16 AC 11 ms
4,908 KB
testcase_17 AC 29 ms
6,972 KB
testcase_18 AC 4 ms
4,380 KB
testcase_19 AC 9 ms
4,380 KB
testcase_20 AC 27 ms
7,268 KB
testcase_21 AC 15 ms
5,388 KB
testcase_22 AC 35 ms
8,476 KB
testcase_23 AC 37 ms
8,560 KB
testcase_24 AC 16 ms
5,852 KB
testcase_25 AC 24 ms
7,496 KB
testcase_26 AC 9 ms
4,956 KB
testcase_27 AC 26 ms
8,848 KB
testcase_28 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)n - 1; i > -1; i--)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ld long double
#define INF 1000000000000000000
typedef pair<ll, ll> pll;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N;
    cin >> N;
    vector<vector<int>> G(N, vector<int>());
    rep(i, N - 1) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    int cnt = 0;
    rep(i, N) {
        if (G[i].size() == 1)
            cnt++;
    }

    cout << max(0, cnt - 2) << endl;
}
0