結果
問題 | No.3113 The farthest point |
ユーザー |
![]() |
提出日時 | 2025-04-18 20:22:03 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 309 ms / 2,000 ms |
コード長 | 905 bytes |
コンパイル時間 | 4,553 ms |
コンパイル使用メモリ | 258,232 KB |
実行使用メモリ | 19,584 KB |
最終ジャッジ日時 | 2025-04-18 20:22:17 |
合計ジャッジ時間 | 9,562 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 33 |
ソースコード
#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; }