結果

問題 No.1928 Make a Binary Tree
ユーザー ruthenruthen
提出日時 2022-05-06 22:31:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,114 bytes
コンパイル時間 2,300 ms
コンパイル使用メモリ 204,500 KB
実行使用メモリ 507,688 KB
最終ジャッジ日時 2023-09-20 03:34:31
合計ジャッジ時間 10,791 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
13,956 KB
testcase_01 AC 4 ms
9,672 KB
testcase_02 AC 5 ms
9,656 KB
testcase_03 AC 5 ms
9,548 KB
testcase_04 AC 5 ms
9,568 KB
testcase_05 AC 5 ms
9,564 KB
testcase_06 AC 5 ms
9,612 KB
testcase_07 AC 5 ms
9,736 KB
testcase_08 AC 5 ms
9,612 KB
testcase_09 AC 5 ms
9,576 KB
testcase_10 AC 5 ms
9,624 KB
testcase_11 AC 5 ms
9,564 KB
testcase_12 AC 5 ms
9,592 KB
testcase_13 AC 5 ms
9,644 KB
testcase_14 AC 5 ms
9,556 KB
testcase_15 AC 10 ms
10,292 KB
testcase_16 AC 9 ms
10,184 KB
testcase_17 AC 8 ms
10,104 KB
testcase_18 AC 10 ms
10,260 KB
testcase_19 AC 5 ms
9,744 KB
testcase_20 AC 8 ms
10,064 KB
testcase_21 AC 7 ms
9,840 KB
testcase_22 AC 8 ms
10,048 KB
testcase_23 AC 7 ms
10,024 KB
testcase_24 AC 10 ms
10,396 KB
testcase_25 AC 11 ms
10,352 KB
testcase_26 AC 201 ms
26,504 KB
testcase_27 AC 115 ms
19,920 KB
testcase_28 AC 132 ms
21,124 KB
testcase_29 AC 242 ms
28,852 KB
testcase_30 AC 105 ms
19,024 KB
testcase_31 AC 151 ms
22,584 KB
testcase_32 AC 238 ms
28,332 KB
testcase_33 AC 123 ms
20,268 KB
testcase_34 AC 148 ms
22,552 KB
testcase_35 AC 80 ms
26,616 KB
testcase_36 TLE -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
testcase_56 -- -
testcase_57 -- -
testcase_58 -- -
testcase_59 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#ifdef _RUTHEN
#include "debug.hpp"
#else
#define show(...) true
#endif

using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
template <class T> using V = vector<T>;

priority_queue<int> que[200005];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    V<V<int>> G(N);
    rep(i, N - 1) {
        int x, y;
        cin >> x >> y;
        x--, y--;
        G[x].push_back(y);
        G[y].push_back(x);
    }
    auto rec = [&](auto f, int cur, int par) -> void {
        for (auto &nex : G[cur]) {
            if (nex == par) continue;
            f(f, nex, cur);
            while (!que[nex].empty()) {
                que[cur].push(que[nex].top());
                que[nex].pop();
            }
        }
        int v = 1, cnt = 0;
        while (!que[cur].empty() && cnt < 2) {
            cnt++;
            v += que[cur].top();
            que[cur].pop();
        }
        que[cur].push(v);
        return;
    };
    rec(rec, 0, -1);
    int ans = que[0].top();
    cout << ans << '\n';
    return 0;
}
0