結果
問題 |
No.1752 Up-Down Tree
|
ユーザー |
![]() |
提出日時 | 2021-11-19 21:47:29 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 651 bytes |
コンパイル時間 | 2,152 ms |
コンパイル使用メモリ | 174,960 KB |
実行使用メモリ | 48,832 KB |
最終ジャッジ日時 | 2024-12-31 22:45:00 |
合計ジャッジ時間 | 6,563 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | WA * 2 |
other | AC * 2 WA * 18 |
ソースコード
#include<bits/stdc++.h> using namespace std; multiset<int,greater<int>> s[100001]; vector<int>g[100001]; void dfs(int now=0,int par=-1){ s[now].emplace(0);s[now].emplace(0); for(int x:g[now]){ if(x==par)continue; dfs(x,now); if(s[now].size()<s[x].size())swap(s[now],s[x]); for(int p:s[x])s[now].emplace(x); } auto itr=s[now].begin(); int res=*itr+1; itr=s[now].erase(itr); res+=*itr; s[now].erase(itr); s[now].emplace(res); } int main(){ int N; cin>>N; for(int i=1;i<N;++i){ int a,b; cin>>a>>b; --a;--b; g[a].emplace_back(b); g[b].emplace_back(a); } dfs(); cout<<*s[0].begin()<<endl; }