結果
問題 | No.2532 Want Play More |
ユーザー |
![]() |
提出日時 | 2023-11-03 21:32:15 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 240 ms / 2,000 ms |
コード長 | 616 bytes |
コンパイル時間 | 2,008 ms |
コンパイル使用メモリ | 196,596 KB |
最終ジャッジ日時 | 2025-02-17 17:45:16 |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 26 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define int long long vector<vector<int>> G(200100); pair<int,int> f(int x, int p){ pair<int,int> ans = {0,1e18}; bool k = true; for(int y:G[x])if(y != p){ pair<int,int> a = f(y,x); ans.first = max(ans.first,a.second+1); ans.second = min(ans.second,a.first+1); k = false; } if(k) ans = {0,0}; return ans; } signed main(){ int N; cin>>N; for(int i=0;i<N-1;i++){ int a,b; cin>>a>>b; a--; b--; G[a].push_back(b); G[b].push_back(a); } pair<int,int> a = f(0,-1); cout<<a.first<<endl;cout<<a.second<<endl; }