結果
| 問題 | No.3113 The farthest point |
| コンテスト | |
| ユーザー |
vjudge1
|
| 提出日時 | 2025-05-01 21:06:33 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.90.0) |
| 結果 |
AC
|
| 実行時間 | 107 ms / 2,000 ms |
| コード長 | 683 bytes |
| 記録 | |
| コンパイル時間 | 1,088 ms |
| コンパイル使用メモリ | 212,512 KB |
| 実行使用メモリ | 17,536 KB |
| 最終ジャッジ日時 | 2026-07-10 10:14:11 |
| 合計ジャッジ時間 | 4,086 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 33 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;
const ll LLINF=0x3f3f3f3f3f3f3f3fLL;
const int MAX=2e5+10;
struct node{int to,w;};
vector<node> mp[MAX];
ll dp[MAX],ans;
void dfs(int x,int fa)
{
int to,w;
ll mx=0;
dp[x]=0;
for(auto &it:mp[x])
{
to=it.to;
w=it.w;
if(to==fa) continue;
dfs(to,x);
ans=max(ans,dp[to]+w);
ans=max(ans,mx+dp[to]+w);
mx=max(mx,dp[to]+w);
}
dp[x]=mx;
}
int main()
{
int n,i,a,b,c;
scanf("%d",&n);
for(i=1;i<=n;i++) mp[i].clear();
for(i=1;i<n;i++)
{
scanf("%d%d%d",&a,&b,&c);
mp[a].push_back({b,c});
mp[b].push_back({a,c});
}
ans=0;
dfs(1,0);
printf("%lld\n",ans);
return 0;
}
vjudge1