結果

問題 No.2532 Want Play More
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2024-03-10 02:23:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 118 ms / 2,000 ms
コード長 1,103 bytes
コンパイル時間 2,552 ms
コンパイル使用メモリ 209,452 KB
実行使用メモリ 35,312 KB
最終ジャッジ日時 2024-03-10 02:23:44
合計ジャッジ時間 6,949 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 114 ms
25,164 KB
testcase_02 AC 118 ms
25,164 KB
testcase_03 AC 105 ms
24,356 KB
testcase_04 AC 104 ms
24,120 KB
testcase_05 AC 100 ms
23,476 KB
testcase_06 AC 83 ms
35,312 KB
testcase_07 AC 3 ms
6,676 KB
testcase_08 AC 5 ms
6,676 KB
testcase_09 AC 5 ms
6,676 KB
testcase_10 AC 47 ms
13,440 KB
testcase_11 AC 65 ms
13,312 KB
testcase_12 AC 78 ms
19,608 KB
testcase_13 AC 55 ms
15,232 KB
testcase_14 AC 18 ms
7,296 KB
testcase_15 AC 109 ms
24,868 KB
testcase_16 AC 88 ms
21,564 KB
testcase_17 AC 4 ms
6,676 KB
testcase_18 AC 67 ms
17,336 KB
testcase_19 AC 93 ms
22,144 KB
testcase_20 AC 2 ms
6,676 KB
testcase_21 AC 2 ms
6,676 KB
testcase_22 AC 2 ms
6,676 KB
testcase_23 AC 2 ms
6,676 KB
testcase_24 AC 2 ms
6,676 KB
testcase_25 AC 2 ms
6,676 KB
testcase_26 AC 1 ms
6,676 KB
testcase_27 AC 1 ms
6,676 KB
testcase_28 AC 64 ms
25,852 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    //dp(i, j) : 頂点iにプレイヤーjがいる状態で始めた時のターン数
    int N, a, b;
    cin >> N;
    vector<vector<int>> E(N+1);
    for (int i=1; i<=N-1; i++){
        cin >> a >> b;
        E[a].push_back(b);
        E[b].push_back(a);
    }

    vector dp(N+1, vector<int>(2));
    for (int i=1; i<=N; i++) dp[i][1] = 1e9;

    auto dfs=[&](auto self, int from, int p)->void{
        if (p != -1 && E[from].size() == 1){
            dp[from][0] = 0;
            dp[from][1] = 0;
            return;
        }
        for (auto to : E[from]){
            if (to == p) continue;
            self(self, to, from);
            //Halcは最大化
            dp[from][0] = max(dp[from][0], dp[to][1]+1);
            //Sappは最小化
            dp[from][1] = min(dp[from][1], dp[to][0]+1);
        }
    };

    dfs(dfs, 1, -1);

    if (N == 1) dp[1][1] = 0;
    cout << dp[1][0] << endl;
    cout << dp[1][1] << endl;

    return 0;
}
0