Submission #122470

#TimeUsernameProblemLanguageResultExecution timeMemory
122470youngyojunBeads and wires (APIO14_beads)C++11
28 / 100
1070 ms5888 KiB
#include <bits/stdc++.h> #define eb emplace_back #define sz(V) ((int)(V).size()) #define allv(V) ((V).begin()),((V).end()) #define upmax(a,b) (a)=max((a),(b)) #define INFLL (0x3f3f3f3f3f3f3f3fll) using namespace std; typedef long long ll; const int MAXN = 200055; ll D[MAXN], E[MAXN]; vector<int> G[MAXN]; int A[MAXN], B[MAXN], C[MAXN]; ll Ans; int N; void f(int i, int p, int pe) { D[i] = 0; E[i] = -INFLL; for(int e : G[i]) { int v = A[e]^B[e]^i; if(v == p) continue; f(v, i, C[e]); upmax(E[i], -max(D[v], E[v]) + D[v] + C[e]); D[i] += max(D[v], E[v]); } E[i] += D[i] + pe; } int main() { ios::sync_with_stdio(false); cin >> N; for(int i = 1; i < N; i++) { cin >> A[i] >> B[i] >> C[i]; G[A[i]].eb(i); G[B[i]].eb(i); } vector<int> O; for(int i = 1; i <= N; i++) O.eb(i); random_shuffle(allv(O)); for(int t = 0; t < N && t <= 4000; t++) { int i = O[t]; ll ret = 0; for(int e : G[i]) { int v = A[e]^B[e]^i; f(v, i, C[e]); ret += max(D[v], E[v]); } upmax(Ans, ret); } cout << Ans << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...