結果

問題 No.1752 Up-Down Tree
ユーザー kiyoshi0205kiyoshi0205
提出日時 2021-11-19 22:26:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 716 bytes
コンパイル時間 1,713 ms
コンパイル使用メモリ 172,728 KB
実行使用メモリ 26,668 KB
最終ジャッジ日時 2023-08-30 09:10:18
合計ジャッジ時間 4,780 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,396 KB
testcase_11 WA -
testcase_12 AC 6 ms
10,404 KB
testcase_13 AC 61 ms
16,620 KB
testcase_14 AC 79 ms
17,648 KB
testcase_15 AC 18 ms
12,036 KB
testcase_16 AC 78 ms
17,812 KB
testcase_17 AC 62 ms
16,368 KB
testcase_18 AC 153 ms
24,584 KB
testcase_19 AC 149 ms
24,412 KB
testcase_20 WA -
testcase_21 WA -
権限があれば一括ダウンロードができます

ソースコード

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