結果

問題 No.1928 Make a Binary Tree
ユーザー ruthen71
提出日時 2022-05-06 22:31:52
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 1,114 bytes
コンパイル時間 10,353 ms
コンパイル使用メモリ 260,192 KB
最終ジャッジ日時 2025-01-29 03:48:12
ジャッジサーバーID
(参考情報)
judge2 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 46 TLE * 11
権限があれば一括ダウンロードができます

ソースコード

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