Submission #123392

#TimeUsernameProblemLanguageResultExecution timeMemory
123392popovicirobertBeads and wires (APIO14_beads)C++14
0 / 100
6 ms5240 KiB
#include <bits/stdc++.h> #define lsb(x) (x & (-x)) #define ll long long #define ull unsigned long long // 217 // 44 /*const int MOD = ; inline int lgput(int a, int b) { int ans = 1; while(b > 0) { if(b & 1) ans = (1LL * ans * a) % MOD; b >>= 1; a = (1LL * a * a) % MOD; } return ans; } inline void mod(int &x) { if(x >= MOD) x -= MOD; } inline void add(int &x, int y) { x += y; mod(x); } inline void sub(int &x, int y) { x += MOD - y; mod(x); } inline void mul(int &x, int y) { x = (1LL * x * y) % MOD; }*/ using namespace std; const int INF = 2e9; const int MAXN = (int) 2e5; vector < pair <int, int> > g[MAXN + 1]; int dp[MAXN + 1][2]; void dfs(int nod, int par) { vector <int> cur(3, -INF); cur[0] = 0; for(auto it : g[nod]) { if(it.first != par) { dfs(it.first, nod); int mx = max(dp[it.first][1] + it.second, dp[it.first][0]); vector <int> aux(3, -INF); aux[0] = cur[0] + mx; aux[1] = max(cur[0] + dp[it.first][0] + it.second, cur[1] + mx); aux[2] = max(cur[1] + dp[it.first][0] + it.second, cur[2] + mx); swap(cur, aux); } } dp[nod][0] = max(cur[0], cur[2]); dp[nod][1] = cur[1]; } int main() { //ifstream cin("A.in"); //ofstream cout("A.out"); int i, n; ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); cin >> n; for(i = 1; i < n; i++) { int x, y, z; cin >> x >> y >> z; g[x].push_back({y, z}); g[y].push_back({x, z}); } dfs(1, 0); cout << dp[1][0]; //cin.close(); //cout.close(); 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...