結果

問題 No.1752 Up-Down Tree
ユーザー kiyoshi0205kiyoshi0205
提出日時 2021-11-19 21:47:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 651 bytes
コンパイル時間 1,915 ms
コンパイル使用メモリ 173,104 KB
実行使用メモリ 48,900 KB
最終ジャッジ日時 2023-08-30 08:01:31
合計ジャッジ時間 6,132 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 5 ms
10,460 KB
testcase_11 AC 6 ms
10,432 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0