結果
| 問題 | No.3113 The farthest point |
| コンテスト | |
| ユーザー |
沙耶花
|
| 提出日時 | 2025-04-18 20:22:03 |
| 言語 | C++17 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
WJ
不安定
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 905 bytes |
| 記録 | |
| 最終ジャッジ日時 | 2026-10-17 00:05:20 |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge5_0 |
(要ログイン)
ソースコード
#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 4000000000000000001LL
long long dp[300000];
long long ans = 0;
void dfs(int v,int p,vector<vector<pair<int,long long>>> &E){
vector<long long> t;
rep(i,E[v].size()){
int to = E[v][i].first;
long long c = E[v][i].second;
if(to == p) continue;
dfs(to,v,E);
t.push_back(dp[to]+c);
}
sort(t.rbegin(),t.rend());
if(t.size()>=2)ans = max(ans,t[0]+t[1]);
if(t.size()>=1){
ans = max(ans,t[0]);
dp[v] = max(t[0],0LL);
}
}
int main(){
int n;
cin>>n;
vector<vector<pair<int,long long>>> E(n);
rep(i,n-1){
int a,b;
long long c;
cin>>a>>b>>c;
a--;
b--;
E[a].push_back({b,c});
E[b].push_back({a,c});
}
dfs(0,-1,E);
cout<<ans<<endl;
return 0;
}
沙耶花