제출 #31621

#제출 시각아이디문제언어결과실행 시간메모리
31621cheater2k구슬과 끈 (APIO14_beads)C++14
28 / 100
1076 ms5248 KiB
#include <bits/stdc++.h> using namespace std; const int N = 200010; const int inf = 2e9 + 12345; int n; int f[N][2]; vector < pair<int,int> > G[N]; int ans; void dfs(int u, int p) { vector < pair<int,int> > ch; for (auto edge: G[u]) if (edge.second != p) { dfs(edge.second, u); ch.push_back(edge); } f[u][1] = -inf; f[u][0] = 0; for (auto edge: ch) { f[u][0] += max(f[edge.second][0], f[edge.second][1] + edge.first); } for (auto edge: ch) { int mx = f[u][0]; mx -= max(f[edge.second][0], f[edge.second][1] + edge.first); mx += (f[edge.second][0] + edge.first); f[u][1] = max(f[u][1], mx); } } void re_dfs(int u, int p) { for (auto edge: G[u]) if (edge.second != p) { } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n; for (int i = 1; i < n; ++i) { int u, v, w; cin >> u >> v >> w; G[u].push_back(make_pair(w,v)); G[v].push_back(make_pair(w,u)); } for (int i = 1; i <= n; ++i) { dfs(i,i); ans = max(ans, f[i][0]); } cout << ans << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...