結果

問題 No.806 木を道に
ユーザー RadperiaRadperia
提出日時 2019-03-23 01:41:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 59 ms / 2,000 ms
コード長 1,299 bytes
コンパイル時間 1,586 ms
コンパイル使用メモリ 171,048 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-19 14:26:18
合計ジャッジ時間 3,490 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 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 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 14 ms
4,348 KB
testcase_11 AC 12 ms
4,348 KB
testcase_12 AC 50 ms
4,352 KB
testcase_13 AC 37 ms
4,348 KB
testcase_14 AC 47 ms
4,352 KB
testcase_15 AC 51 ms
4,352 KB
testcase_16 AC 19 ms
4,348 KB
testcase_17 AC 43 ms
4,348 KB
testcase_18 AC 6 ms
4,348 KB
testcase_19 AC 14 ms
4,348 KB
testcase_20 AC 44 ms
4,348 KB
testcase_21 AC 25 ms
4,348 KB
testcase_22 AC 59 ms
4,352 KB
testcase_23 AC 59 ms
4,352 KB
testcase_24 AC 31 ms
4,348 KB
testcase_25 AC 46 ms
4,352 KB
testcase_26 AC 18 ms
4,348 KB
testcase_27 AC 58 ms
4,352 KB
testcase_28 AC 3 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define INF 1145141919
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
int ny, nx;
typedef long long int ll;
using namespace std;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

ll llpow(ll x, ll y)
{
    ll ans = 1;
    REP(i, y)
    ans *= x;
    return ans;
}

int ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return 0;
}
////////////////////////////////////////////////////////////////////
int main()
{
    int N; cin >> N;
    vector<pair<int,int>> node(N);
    vector<int> cnt(N+1);
    REP(i,N-1) cin >> node[i].first >> node[i].second;

    REP(i,N){
        cnt[node[i].first]++;
        cnt[node[i].second]++;
    }

    /*REP(i,N){
        cout <<"i= "<< i+1 << " cnt[i]= " << cnt[i+1] << endl;
    }

    cout << endl;*/

    ll res=0, remain=0;

    REP(i,N){
        if(cnt[i+1]==1) res++;
        else if(cnt[i+1]>1) remain+=cnt[i+1]-2;
    }

    //cout << res << " " << remain << endl;

    cout << remain << endl;

    return 0;
}
0