Submission #564002

#TimeUsernameProblemLanguageResultExecution timeMemory
564002hollwo_pelwBeads and wires (APIO14_beads)C++17
0 / 100
5 ms8148 KiB
#include <bits/stdc++.h> // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/trie_policy.hpp> // #include <ext/rope> using namespace std; // using namespace __gnu_cxx; // using namespace __gnu_pbds; void Hollwo_Pelw(); signed main(){ #ifndef hollwo_pelw_local if (fopen(".inp", "r")) assert(freopen(".inp", "r", stdin)), assert(freopen(".out", "w", stdout)); #else using namespace chrono; auto start = steady_clock::now(); #endif cin.tie(0), cout.tie(0) -> sync_with_stdio(0); int testcases = 1; // cin >> testcases; for (int test = 1; test <= testcases; test++){ // cout << "Case #" << test << ": "; Hollwo_Pelw(); } #ifdef hollwo_pelw_local auto end = steady_clock::now(); cout << "\nExecution time : " << duration_cast<milliseconds> (end - start).count() << "[ms]" << endl; #endif } const int N = 2e5 + 5; int n, dp[N][4]; vector<pair<int, int>> adj[N]; void solve(int u, int p) { dp[u][0] = 0; for (auto [v, w] : adj[u]) if (v != p) { solve(v, u); for (int i = 3; i --; ) { if (i < 2) { dp[u][i + 1] = max({ dp[u][i + 1], dp[u][i] + w + max(dp[v][0], dp[v][2]), }); } dp[u][i] = max({ dp[u][i], dp[u][i] + w + dp[v][1], dp[u][i] + max(dp[v][0], dp[v][2]) }); } } } void Hollwo_Pelw(){ cin >> n; memset(dp, -0x3f, sizeof dp); for (int i = 1, u, v, w; i < n; i++) { cin >> u >> v >> w; adj[u].emplace_back(v, w); adj[v].emplace_back(u, w); } solve(1, 0); cout << max({dp[1][0], dp[1][2]}); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...