結果

問題 No.2532 Want Play More
ユーザー maksimmaksim
提出日時 2023-11-03 22:16:02
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 146 ms / 2,000 ms
コード長 829 bytes
コンパイル時間 1,926 ms
コンパイル使用メモリ 169,672 KB
実行使用メモリ 45,740 KB
最終ジャッジ日時 2024-09-25 20:39:41
合計ジャッジ時間 4,689 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

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