結果

問題 No.806 木を道に
ユーザー kagasankagasan
提出日時 2020-04-25 17:31:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 79 ms / 2,000 ms
コード長 1,626 bytes
コンパイル時間 1,822 ms
コンパイル使用メモリ 172,172 KB
実行使用メモリ 9,600 KB
最終ジャッジ日時 2024-04-25 00:59:50
合計ジャッジ時間 4,523 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,760 KB
testcase_01 AC 4 ms
6,016 KB
testcase_02 AC 4 ms
5,888 KB
testcase_03 AC 3 ms
5,888 KB
testcase_04 AC 3 ms
5,888 KB
testcase_05 AC 4 ms
6,144 KB
testcase_06 AC 3 ms
5,760 KB
testcase_07 AC 3 ms
5,888 KB
testcase_08 AC 3 ms
5,888 KB
testcase_09 AC 3 ms
5,888 KB
testcase_10 AC 20 ms
6,784 KB
testcase_11 AC 16 ms
6,656 KB
testcase_12 AC 67 ms
9,088 KB
testcase_13 AC 47 ms
8,320 KB
testcase_14 AC 64 ms
8,832 KB
testcase_15 AC 68 ms
9,088 KB
testcase_16 AC 24 ms
6,912 KB
testcase_17 AC 62 ms
8,704 KB
testcase_18 AC 9 ms
6,144 KB
testcase_19 AC 20 ms
6,656 KB
testcase_20 AC 57 ms
8,576 KB
testcase_21 AC 34 ms
7,552 KB
testcase_22 AC 79 ms
9,600 KB
testcase_23 AC 77 ms
9,600 KB
testcase_24 AC 38 ms
7,552 KB
testcase_25 AC 55 ms
8,448 KB
testcase_26 AC 22 ms
6,964 KB
testcase_27 AC 66 ms
9,360 KB
testcase_28 AC 5 ms
6,016 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P>IP;
typedef vector<ll> V;
typedef vector<V> V2;
typedef vector<vector<P> > G;
void g_dir(G &graph, ll a, ll b, ll w = 1){graph[a].push_back(P(b, w));}
void g_undir(G &graph, ll a, ll b, ll w = 1){g_dir(graph, a, b, w);g_dir(graph, b, a, w);}
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}
const ll INF = 1145141919;
const ll MOD = 1000000007;
const ll NUM = 101010;

V path[101010];
ll dep[101010];
ll N;
void bfs(ll rt){
    rep1(i, N)dep[i] = INF;
    queue<ll>Q;
    Q.push(rt);
    dep[rt] = 0;
    while(!Q.empty()){
        ll idx = Q.front();
        Q.pop();
        for(auto to : path[idx]){
            if(dep[to] == INF){
                dep[to] = dep[idx] + 1;
                Q.push(to);
            }
        }
    }
}


int main(){

    cin >> N;
    rep(i, N - 1){
        ll a, b;
        cin >> a >> b;
        path[a].push_back(b);
        path[b].push_back(a);
    }
    
    ll ans = 0;
    rep1(i, N)if(path[i].size() > 2)ans += (path[i].size() - 2);
    cout << ans << endl;
    return 0;
    
    bfs(1);
    ll nxt = 1;
    rep1(i, N)if(dep[i] > dep[nxt])nxt = i;
    bfs(nxt);
    ll tmp = 0;
    rep1(i, N)chmax(tmp, dep[i]);
    cout << N - 1 - tmp << endl;

    

    return 0;
}
0