結果
問題 | No.2532 Want Play More |
ユーザー |
|
提出日時 | 2023-11-03 22:05:45 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 161 ms / 2,000 ms |
コード長 | 638 bytes |
コンパイル時間 | 851 ms |
コンパイル使用メモリ | 70,560 KB |
実行使用メモリ | 33,024 KB |
最終ジャッジ日時 | 2024-09-25 20:28:19 |
合計ジャッジ時間 | 3,989 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 26 |
ソースコード
#include<iostream> #include<vector> #include<cassert> using namespace std; int N; vector<int>G[2<<17]; int ans[2<<17][2]; void dfs(int u,int p) { int ch=0; for(int v:G[u])if(v!=p) { dfs(v,u); ch++; } if(ch==0)ans[u][0]=ans[u][1]=0; else { ans[u][0]=0; ans[u][1]=1e9; for(int v:G[u])if(v!=p) { ans[u][0]=max(ans[u][0],ans[v][1]+1); ans[u][1]=min(ans[u][1],ans[v][0]+1); } } } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin>>N; for(int i=1;i<N;i++) { int u,v;cin>>u>>v; u--,v--; G[u].push_back(v); G[v].push_back(u); } dfs(0,-1); cout<<ans[0][0]<<endl; cout<<ans[0][1]<<endl; }