結果

問題 No.2532 Want Play More
ユーザー maksimmaksim
提出日時 2023-11-03 22:16:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 162 ms / 2,000 ms
コード長 829 bytes
コンパイル時間 1,733 ms
コンパイル使用メモリ 170,836 KB
実行使用メモリ 45,932 KB
最終ジャッジ日時 2023-11-03 22:16:07
合計ジャッジ時間 5,032 ms
ジャッジサーバーID
(参考情報)
judge11 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
8,848 KB
testcase_01 AC 162 ms
18,884 KB
testcase_02 AC 154 ms
18,892 KB
testcase_03 AC 161 ms
18,588 KB
testcase_04 AC 153 ms
18,508 KB
testcase_05 AC 143 ms
18,304 KB
testcase_06 AC 91 ms
45,932 KB
testcase_07 AC 5 ms
9,020 KB
testcase_08 AC 7 ms
9,272 KB
testcase_09 AC 7 ms
9,204 KB
testcase_10 AC 56 ms
14,880 KB
testcase_11 AC 49 ms
14,824 KB
testcase_12 AC 119 ms
16,984 KB
testcase_13 AC 61 ms
15,488 KB
testcase_14 AC 20 ms
12,752 KB
testcase_15 AC 161 ms
18,796 KB
testcase_16 AC 134 ms
17,648 KB
testcase_17 AC 6 ms
9,140 KB
testcase_18 AC 93 ms
16,212 KB
testcase_19 AC 131 ms
17,836 KB
testcase_20 AC 4 ms
8,848 KB
testcase_21 AC 5 ms
8,848 KB
testcase_22 AC 4 ms
8,844 KB
testcase_23 AC 4 ms
8,848 KB
testcase_24 AC 4 ms
8,848 KB
testcase_25 AC 4 ms
8,844 KB
testcase_26 AC 4 ms
8,844 KB
testcase_27 AC 4 ms
8,848 KB
testcase_28 AC 54 ms
21,960 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
#define int long long
const int maxn=2e5+5;
vector<int> a[maxn];
pair<int,int> dp[maxn];
bool used[maxn];
void dfs(int x)
{
    used[x]=true;
    vector<int> ch;
    for(int v:a[x])
    {
        if(!used[v])
        {
            ch.push_back(v);
            dfs(v);
        }
    }
    if(ch.empty())
    {
        dp[x]={0,0};return;
    }
    dp[x].second=1e18;
    for(int v:ch)
    {
        dp[x].first=max(dp[x].first,dp[v].second+1);
        dp[x].second=min(dp[x].second,dp[v].first+1);
    }
}
int32_t main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n;cin>>n;
    for(int i=0;i<n-1;++i)
    {
        int x,y;cin>>x>>y;--x;--y;a[x].push_back(y);a[y].push_back(x);
    }
    dfs(0);
    cout<<dp[0].first<<'\n'<<dp[0].second;
    return 0;
}
0