結果

問題 No.2532 Want Play More
ユーザー 👑 hitonanodehitonanode
提出日時 2023-11-03 22:33:04
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 112 ms / 2,000 ms
コード長 806 bytes
コンパイル時間 922 ms
コンパイル使用メモリ 92,028 KB
実行使用メモリ 21,056 KB
最終ジャッジ日時 2023-11-03 22:33:10
合計ジャッジ時間 3,411 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 112 ms
14,192 KB
testcase_02 AC 106 ms
14,192 KB
testcase_03 AC 102 ms
13,664 KB
testcase_04 AC 109 ms
13,664 KB
testcase_05 AC 99 ms
13,400 KB
testcase_06 AC 62 ms
21,056 KB
testcase_07 AC 3 ms
4,348 KB
testcase_08 AC 4 ms
4,348 KB
testcase_09 AC 4 ms
4,348 KB
testcase_10 AC 42 ms
8,452 KB
testcase_11 AC 40 ms
8,188 KB
testcase_12 AC 69 ms
11,288 KB
testcase_13 AC 48 ms
9,244 KB
testcase_14 AC 15 ms
5,284 KB
testcase_15 AC 99 ms
14,192 KB
testcase_16 AC 76 ms
12,344 KB
testcase_17 AC 3 ms
4,348 KB
testcase_18 AC 65 ms
10,300 KB
testcase_19 AC 79 ms
12,608 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 1 ms
4,348 KB
testcase_26 AC 1 ms
4,348 KB
testcase_27 AC 1 ms
4,348 KB
testcase_28 AC 44 ms
14,992 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);

    int N;
    cin >> N;
    vector<vector<int>> to(N);
    for (int e = 0; e < N - 1; ++e) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        to.at(a).push_back(b);
        to.at(b).push_back(a);
    }

    auto rec = [&](auto &&self, int now, int prv, bool f) -> int {
        int cur = f ? 0 : 1 << 20;

        int nch = 0;
        for (int nxt : to.at(now)) {
            if (nxt == prv) continue;
            ++nch;
            if (int tmp = self(self, nxt, now, !f) + 1; (f and cur < tmp) or (!f and cur > tmp)) cur = tmp;
        }

        return nch ? cur : 0;
    };

    cout << rec(rec, 0, -1, true) << '\n';
    cout << rec(rec, 0, -1, false) << '\n';
}
0