結果

問題 No.806 木を道に
ユーザー beetbeet
提出日時 2019-03-22 21:22:46
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 775 bytes
コンパイル時間 2,344 ms
コンパイル使用メモリ 208,044 KB
実行使用メモリ 15,708 KB
最終ジャッジ日時 2023-10-19 06:19:27
合計ジャッジ時間 4,314 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 2 ms
4,348 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 WA -
testcase_11 WA -
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 -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 43 ms
11,484 KB
testcase_25 AC 66 ms
15,708 KB
testcase_26 AC 21 ms
5,316 KB
testcase_27 AC 68 ms
10,140 KB
testcase_28 AC 3 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  vector<vector<Int> > G(n);
  for(Int i=1;i<n;i++){
    Int x,y;
    cin>>x>>y;
    x--;y--;
    G[x].emplace_back(y);
    G[y].emplace_back(x);
  }
  vector<Int> dep(n);
  Int s=0;
  function<void(Int, Int, Int)> dfs=
    [&](Int v,Int p,Int d){
      dep[v]=d;
      for(Int u:G[v]){
        if(u==p) continue;
        dfs(u,v,d+1);
      }
      if(dep[s]<dep[v]) s=v;
    };
  dfs(0,-1,0);
  dfs(s,-1,0);
  Int ans=n-(*max_element(dep.begin(),dep.end())+1);
  cout<<ans<<endl;
  return 0;
}
0