#include <bits/stdc++.h>
using namespace std;
#define int long long
vector<vector<pair<long long,pair<int,int>>>>g(3e5+5);
vector<long long>dp2(3e5+5,1e9+5);
vector<long long>dp(3e5+5,0);
void dfs(int v=1,int p=-1,int w=0)
{
if(p==-1)dp[v] = 0;
else dp[v] = dp[p] + w;
for(auto u : g[v])
{
if(p != u.second.first)
{
dp2[u.second.first]= min(dp2[v],u.second.second);
dfs(u.second.first,v,u.first);
}
}
}
int main()
{
int n,m;
cin >> n>>m;
cin >> n >> m;
vector<long long>mx(m+2);
for(int i = 1;i<n;i++)
{
int a,b,w;
cin >> a >> b >> w;
g[a].push_back({w,{b,i}});
g[b].push_back({w,{a,i}});
mx[i] = w;
}
for(int i = n-1;i> 0;i--)
{
mx[i] = max(mx[i+1],mx[i]);
}
dfs();
long long ans = dp[n] + mx[dp2[n]+1];
cout << ans;
}
Compilation message
cc1plus: error: '::main' must return 'int'