結果

問題 No.2532 Want Play More
ユーザー momoyuumomoyuu
提出日時 2023-11-05 12:41:24
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 124 ms / 2,000 ms
コード長 694 bytes
コンパイル時間 3,215 ms
コンパイル使用メモリ 247,544 KB
実行使用メモリ 28,620 KB
最終ジャッジ日時 2023-11-05 12:41:32
合計ジャッジ時間 7,717 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,348 KB
testcase_01 AC 107 ms
16,232 KB
testcase_02 AC 103 ms
16,236 KB
testcase_03 AC 100 ms
15,724 KB
testcase_04 AC 92 ms
15,588 KB
testcase_05 AC 124 ms
15,244 KB
testcase_06 AC 77 ms
28,620 KB
testcase_07 AC 4 ms
4,348 KB
testcase_08 AC 6 ms
4,348 KB
testcase_09 AC 6 ms
4,348 KB
testcase_10 AC 42 ms
9,504 KB
testcase_11 AC 41 ms
9,396 KB
testcase_12 AC 68 ms
13,020 KB
testcase_13 AC 49 ms
10,524 KB
testcase_14 AC 16 ms
5,924 KB
testcase_15 AC 100 ms
16,072 KB
testcase_16 AC 80 ms
14,160 KB
testcase_17 AC 4 ms
4,348 KB
testcase_18 AC 58 ms
11,740 KB
testcase_19 AC 85 ms
14,448 KB
testcase_20 AC 3 ms
4,348 KB
testcase_21 AC 3 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 3 ms
4,348 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 2 ms
4,348 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 54 ms
16,708 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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


int n;
vector<int> g[2<<17];
int dp[2<<17][2];

void dfs(int ni,int p){
    dp[ni][1] = 1e9;
    for(auto&to:g[ni]) if(to!=p){
        dfs(to,ni);
        dp[ni][0] = max(dp[ni][0],dp[to][1]);
        dp[ni][1] = min(dp[ni][1],dp[to][0]);
    }
    if(dp[ni][1]==1e9) dp[ni][1] = 0;
    dp[ni][0] += 1;
    dp[ni][1] += 1;
    return ;
}

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

    cin>>n;
    for(int i = 0;i<n-1;i++){
        int u,v;
        cin>>u>>v;
        u--;v--;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    dfs(0,-1);
    cout<<dp[0][0]-1<<"\n"<<dp[0][1]-1<<"\n";
}
0