#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);
}
}
}
signed 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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
14 ms |
24152 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
14 ms |
24152 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
16 ms |
27988 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
16 ms |
27992 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
62 ms |
34364 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
62 ms |
34364 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
14 ms |
24152 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |