結果

問題 No.1752 Up-Down Tree
ユーザー kiyoshi0205kiyoshi0205
提出日時 2021-11-19 22:27:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 717 bytes
コンパイル時間 2,028 ms
コンパイル使用メモリ 171,592 KB
実行使用メモリ 26,596 KB
最終ジャッジ日時 2023-08-30 09:12:03
合計ジャッジ時間 5,212 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
23,044 KB
testcase_01 AC 126 ms
22,972 KB
testcase_02 AC 130 ms
23,088 KB
testcase_03 AC 130 ms
23,008 KB
testcase_04 AC 139 ms
23,180 KB
testcase_05 AC 135 ms
23,044 KB
testcase_06 AC 146 ms
23,220 KB
testcase_07 AC 146 ms
23,068 KB
testcase_08 AC 79 ms
14,040 KB
testcase_09 AC 157 ms
26,596 KB
testcase_10 WA -
testcase_11 AC 5 ms
10,388 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 5 ms
10,448 KB
testcase_21 AC 5 ms
10,672 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
multiset<int,greater<int>> s[100001];
vector<int>g[100001];
bool ch[100001];
void dfs(int now=0,int par=-1){
  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);
  }
  ch[now]=s[now].size()>1;
  if(ch[now]){
    auto itr=s[now].begin();
    int res=*itr+1;
    itr=s[now].erase(itr);
    res+=*itr;
    s[now].erase(itr);
    s[now].emplace(res);
  }else s[now].emplace(1);
}
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()+!ch[0]<<endl;
}
0