結果

問題 No.1928 Make a Binary Tree
ユーザー ruthenruthen
提出日時 2022-05-07 01:55:43
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,431 bytes
コンパイル時間 2,114 ms
コンパイル使用メモリ 213,576 KB
実行使用メモリ 814,412 KB
最終ジャッジ日時 2023-09-20 10:13:13
合計ジャッジ時間 8,598 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
12,744 KB
testcase_01 AC 4 ms
12,760 KB
testcase_02 AC 5 ms
12,804 KB
testcase_03 AC 6 ms
12,752 KB
testcase_04 AC 5 ms
12,736 KB
testcase_05 AC 5 ms
12,736 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 AC 91 ms
32,816 KB
testcase_36 WA -
testcase_37 AC 94 ms
37,564 KB
testcase_38 AC 5 ms
12,748 KB
testcase_39 MLE -
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>;

map<int, int> mp[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);
            for (auto &[val, cnt] : mp[nex]) {
                if (val > 0) mp[cur][val] += cnt;
            }
        }
        if (mp[cur].size() == 0) {
            mp[cur][1] += 1;
            return;
        }
        auto [val, cnt] = *mp[cur].rbegin();
        if (cnt >= 2) {
            mp[cur][val] -= 2;
            mp[cur][2 * val + 1] += 1;
        } else {
            mp[cur].erase(val);
            int ret = val;
            if (mp[cur].size() > 0) {
                auto [val2, cnt2] = *mp[cur].rbegin();
                mp[cur][val2] -= 1;
                ret += val2;
            }
            mp[cur][ret + 1] += 1;
        }
        return;
    };
    rec(rec, 0, -1);
    int ans = (*mp[0].rbegin()).first;
    cout << ans << '\n';
    return 0;
}
0