# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1088231 | 2024-09-14T07:02:02 Z | Rolo678 | Aesthetic (NOI20_aesthetic) | C++14 | 0 ms | 0 KB |
#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; }