Submission #42208

#TimeUsernameProblemLanguageResultExecution timeMemory
42208Aidyn_ABeads and wires (APIO14_beads)C++14
28 / 100
1075 ms5248 KiB
#include <stdio.h> #include <bits/stdc++.h> #define pb push_back #define pf push_front #define pp pop_back #define sz(a) (int)(a.size()) #define mp make_pair #define F first #define S second #define next _next #define prev _prev #define left _left #define right _right #define y1 _y1 #define all(x) x.begin(), x.end() #define what_is(x) #x << " is " << (x) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int N = (int)1e5 + 123; const ll INF = (ll)1e18 + 123; const int inf = (int)1e9 + 123; const int MOD = (int)1e9 + 7; void megaRandom() { unsigned int FOR; asm("rdtsc" : "=A"(FOR)); srand(FOR); } int n; vector<pii> g[N]; ll dp[3][N], res; void dfs(int x, int pr = 0, int par_edge = 0) { ll sum = 0; for(auto to : g[x]) { if(to.F == pr) continue; dfs(to.F, x, to.S); sum += max(dp[0][to.F], dp[1][to.F]); } dp[0][x] = sum; for(auto to : g[x]) { if(to.F == pr) continue; dp[1][x] = max(dp[1][x], dp[0][to.F] + to.S + par_edge + (sum - max(dp[0][to.F], dp[1][to.F])) ); } } int main() { megaRandom(); cin >> n; for(int i = 1, x, y, z; i < n; i ++) { cin >> x >> y >> z; g[x].pb(mp(y, z)); g[y].pb(mp(x, z)); } for(int root = 1; root <= n; root ++) { memset(dp, 0, sizeof dp); dfs(root); res = max(res, dp[0][root]); } cout << res; 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...