結果

問題 No.1928 Make a Binary Tree
ユーザー NanashimaNanashima
提出日時 2022-05-06 22:54:36
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 967 bytes
コンパイル時間 1,878 ms
コンパイル使用メモリ 172,636 KB
実行使用メモリ 33,532 KB
最終ジャッジ日時 2023-09-20 04:31:22
合計ジャッジ時間 11,107 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 150 ms
25,488 KB
testcase_37 WA -
testcase_38 AC 2 ms
4,380 KB
testcase_39 AC 181 ms
24,204 KB
testcase_40 AC 185 ms
24,436 KB
testcase_41 AC 176 ms
24,168 KB
testcase_42 AC 176 ms
24,484 KB
testcase_43 AC 174 ms
24,480 KB
testcase_44 AC 174 ms
24,412 KB
testcase_45 AC 173 ms
24,204 KB
testcase_46 AC 173 ms
24,276 KB
testcase_47 AC 172 ms
24,348 KB
testcase_48 AC 172 ms
24,436 KB
testcase_49 AC 154 ms
33,532 KB
testcase_50 AC 225 ms
14,964 KB
testcase_51 AC 217 ms
14,732 KB
testcase_52 AC 213 ms
14,716 KB
testcase_53 AC 216 ms
14,792 KB
testcase_54 AC 222 ms
14,916 KB
testcase_55 AC 150 ms
25,180 KB
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 AC 143 ms
17,716 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define INF ((1LL<<62)-(1LL<<31))
#define all(a)  (a).begin(),(a).end()
#define rall(a)  (a).rbegin(),(a).rend()
typedef long long ll;
typedef pair<ll,ll> pl;

ll dfs(vector<vector<int>> &g,int pos,int par,priority_queue<ll,vector<ll>> &pq) {
    ll cnt=0,ret=1;
    for(auto nv:g[pos]) {
        if(nv==par) continue;
        cnt++;
        ll res=dfs(g,nv,pos,pq);
        pq.push(res);
    }
    if(cnt==0) return 1;
    rep(i,2) {
        if(pq.empty()) break;
        ret+=pq.top();
        pq.pop();
    }
    return ret;
}

int main() {
    ll n;
    cin >> n;
    vector<vector<int>> g(n,vector<int> ());
    vector<int> deg(n,0);
    rep(i,n-1) {
        int u,v;
        cin >> u >> v;
        u--; v--;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    priority_queue<ll,vector<ll>> pq;
    ll ans=dfs(g,0,-1,pq);
    cout << ans << endl;
    return 0;
}
0