結果
| 問題 |
No.806 木を道に
|
| コンテスト | |
| ユーザー |
addeight2
|
| 提出日時 | 2019-03-23 10:18:53 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 629 bytes |
| コンパイル時間 | 1,645 ms |
| コンパイル使用メモリ | 161,748 KB |
| 実行使用メモリ | 11,136 KB |
| 最終ジャッジ日時 | 2024-09-22 01:02:15 |
| 合計ジャッジ時間 | 3,334 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 9 WA * 18 |
ソースコード
#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;
}
addeight2