Submission #546228

#TimeUsernameProblemLanguageResultExecution timeMemory
546228Ooops_sorryBeads and wires (APIO14_beads)C++14
0 / 100
4 ms5036 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define pb push_back #define ld double #define ll __int128 mt19937 rnd(51); const int N = 2e5 + 10, INF = 1e18; vector<pair<int,int>> g[N]; int res[N][2]; void dfs(int v, int p) { vector<int> dp(3, -INF); dp[0] = 0; for (auto [to, c] : g[v]) { if (to != p) { dfs(to, v); vector<int> dpp(3); for (int j = 0; j < 2; j++) { dpp[j + 1] = max(dpp[j + 1], dp[j] + res[to][0] + c); } for (int j = 0; j < 3; j++) { dpp[j] = max(dpp[j], dp[j] + max(res[to][1] + c, res[to][0])); } swap(dp, dpp); } } res[v][0] = max(dp[0], dp[2]); res[v][1] = dp[1]; } signed main() { #ifdef LOCAL freopen("input.txt", "r", stdin); #endif // LOCAL ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; for (int i = 0; i < n - 1; i++) { int a, b, c; cin >> a >> b >> c; a--, b--; g[a].pb({b, c}); g[b].pb({a, c}); } dfs(0, -1); cout << res[0][0] << endl; return 0; }

Compilation message (stderr)

beads.cpp: In function 'void dfs(long long int, long long int)':
beads.cpp:19:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   19 |     for (auto [to, c] : g[v]) {
      |               ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...