結果

問題 No.806 木を道に
ユーザー addeight2addeight2
提出日時 2019-03-23 10:18:53
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 629 bytes
コンパイル時間 2,218 ms
コンパイル使用メモリ 163,912 KB
実行使用メモリ 11,528 KB
最終ジャッジ日時 2023-10-21 23:34:25
合計ジャッジ時間 5,562 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,044 KB
testcase_01 AC 2 ms
6,044 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 3 ms
6,048 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 3 ms
6,048 KB
testcase_08 AC 3 ms
6,044 KB
testcase_09 AC 2 ms
6,048 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 20 ms
9,660 KB
testcase_25 AC 29 ms
11,528 KB
testcase_26 AC 10 ms
7,216 KB
testcase_27 AC 29 ms
10,172 KB
testcase_28 AC 3 ms
6,180 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
using namespace std;
ll N;
const ll MAX_N=1e5;
vector<ll> G[MAX_N];
ll dst[MAX_N];
void dfs(ll v,ll p,ll d){
	dst[v]=d;
	for(auto e:G[v]){
		if(e!=p){
			dfs(e,v,d+1);
		}
	}
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>N;
	REP(i,N-1){
		ll a,b;
		cin>>a>>b;
		a--;
		b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	dfs(0,-1,0);
	ll v=0;
	REP(i,N){
		if(dst[i]>dst[v]){
			v=i;
		}
	}
	dfs(v,-1,0);
	ll ans=0;
	REP(i,N){
		ans=max(ans,dst[i]);
	}
	ans*=-1;
	ans+=N-1;
	cout<<ans<<endl;
		
}
0