結果

問題 No.806 木を道に
ユーザー mamumamura1mamumamura1
提出日時 2019-03-23 11:31:08
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,036 bytes
コンパイル時間 1,425 ms
コンパイル使用メモリ 170,872 KB
実行使用メモリ 12,104 KB
最終ジャッジ日時 2023-10-22 02:05:03
合計ジャッジ時間 4,166 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
5,676 KB
testcase_01 AC 3 ms
5,676 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 3 ms
5,676 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 3 ms
5,676 KB
testcase_08 AC 3 ms
5,676 KB
testcase_09 AC 3 ms
5,676 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 17 ms
10,016 KB
testcase_25 AC 24 ms
12,104 KB
testcase_26 AC 9 ms
7,136 KB
testcase_27 AC 23 ms
9,816 KB
testcase_28 AC 3 ms
6,104 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr<<"!"<<" "<<(hoge)<<endl;
#define DBG cerr<<"!"<<endl;
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
vvi E(111111);
ll po=0;
ll leng=0;
bool vis[111111];
void dfs(ll now,ll len){
  if(len>leng){
    leng=len;
    po=now;
  }
  for(auto a:E[now]){
    if(vis[a]==false){
      vis[a]=true;
      dfs(a,len+1);
    }
  }
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;cin>>n;
  for(int i=0;i<n-1;i++){
    ll a,b;cin>>a>>b;
    --a;--b;
    E[a].pb(b);
    E[b].pb(a);
  }
  vis[0]=true;
  dfs(0,0);
  leng=0;
  for(int i=0;i<111111;i++)vis[i]=false;
  dfs(po,0);
  cout<<n-1-leng<<endl;
  return 0;
}
0