結果

問題 No.1752 Up-Down Tree
ユーザー kiyoshi0205kiyoshi0205
提出日時 2021-11-19 21:52:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 651 bytes
コンパイル時間 1,681 ms
コンパイル使用メモリ 172,648 KB
実行使用メモリ 48,664 KB
最終ジャッジ日時 2023-08-30 08:13:27
合計ジャッジ時間 5,995 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 217 ms
36,928 KB
testcase_01 AC 218 ms
36,932 KB
testcase_02 AC 139 ms
23,000 KB
testcase_03 AC 141 ms
23,044 KB
testcase_04 AC 193 ms
29,884 KB
testcase_05 AC 203 ms
32,360 KB
testcase_06 AC 179 ms
27,832 KB
testcase_07 AC 181 ms
27,580 KB
testcase_08 AC 175 ms
39,336 KB
testcase_09 AC 245 ms
48,664 KB
testcase_10 AC 5 ms
10,548 KB
testcase_11 AC 5 ms
10,384 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 AC 6 ms
10,372 KB
testcase_21 AC 5 ms
10,400 KB
権限があれば一括ダウンロードができます

ソースコード

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(p);
  }
  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