#include <bits/std++.h>
using namespace std;
vector<vector<pair<long long,pair<int,int>>>>g(3e5+5);
vector<long long>dp2(3e5+5,1e9+5);
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)
{
dp2[u]= 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}});
m[i+1] = 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
Aesthetic.cpp:1:10: fatal error: bits/std++.h: No such file or directory
1 | #include <bits/std++.h>
| ^~~~~~~~~~~~~~
compilation terminated.