Submission #412735

#TimeUsernameProblemLanguageResultExecution timeMemory
412735LastRoninBeads and wires (APIO14_beads)C++14
0 / 100
1 ms460 KiB
#pragma GCC optimize("O3") #include <bits/stdc++.h> #define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); #define ll long long #define pb push_back #define mp make_pair #define f first #define s second #define pill pair<ll, ll> using namespace std; const ll N = 1e4 + 10; const ll big = 1e9; ll n; vector<pair<int,int>> g[N]; int p[N], str[N], zn[N], dp2[N][3], cnt = 1; int ans; int main() { speed; cin >> n; for(int i = 1, a, b, c; i < n; i++) cin >> a >> b >> c, g[a].pb(mp(b, c)), g[b].pb(mp(a, c)); for(int i = 1; i <= n; i++) { str[0] = i; cnt = 1; p[i] = 0; for(int j = 0; j < n; j++) { dp2[j + 1][0] = 0, dp2[j + 1][1] = dp2[j + 1][2] = -big; for(auto u : g[str[j]]) { if(p[str[j]] != u.f) { str[++cnt] = u.f, p[u.f] = str[j],zn[u.f] = u.s; } } } for(int j = n - 1; j >= 0; j--) { int v = str[j], pp = p[v]; int z = max(dp2[v][0], dp2[v][1] + zn[v]); dp2[pp][2] = max(dp2[pp][2] + z, dp2[pp][1] + dp2[v][0] + zn[v]); dp2[pp][1] = max(dp2[pp][1] + z, dp2[pp][0] + dp2[v][0] + zn[v]); dp2[pp][0] = dp2[pp][0] + z; ans = max(ans, dp2[v][2]); } } cout << ans; } /* 10 5 6 9 2 3 5 1 10 8 4 5 9 2 7 8 5 7 10 6 9 4 2 8 9 1 7 5 10 4 10 2 1 2 21 1 3 13 6 7 1 7 9 5 2 4 3 2 5 8 1 6 55 6 8 34 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...