結果
| 問題 |
No.3113 The farthest point
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-04-19 07:35:36 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 807 bytes |
| コンパイル時間 | 2,026 ms |
| コンパイル使用メモリ | 164,200 KB |
| 実行使用メモリ | 20,040 KB |
| 最終ジャッジ日時 | 2025-04-19 07:35:43 |
| 合計ジャッジ時間 | 5,615 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 20 WA * 13 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(ll i=0;i<ll(n);i++)
vector<P> g[200010];
ll vis[200010];
ll n,v,vx,mx=-1000000000000000000;
void dfs(ll x,ll d){
if(d>mx){
mx=d; vx=x;
}
vis[x]=1;
for(ll i=0;i<(ll)g[x].size();i++){
ll p=g[x][i].first,q=g[x][i].second;
if(vis[p]==0) dfs(p,d+q);
}
}
int main(void){
cin.tie(nullptr); ios_base::sync_with_stdio(false);
ll i,j;
cin >> n;
for(i=1;i<n;i++){
ll s,t,w;
cin >> s >> t >> w;
g[s].push_back(P(t,w));
g[t].push_back(P(s,w));
}
dfs(1,0);
mx=-1000000000000000000;
for(i=0;i<=n;i++) vis[i]=0;
v=vx;
dfs(v,0);
cout << max(0LL,mx) << endl;
return 0;
}