Submission #404139

#TimeUsernameProblemLanguageResultExecution timeMemory
404139opukittpceno_hhrBeads and wires (APIO14_beads)C++17
28 / 100
1090 ms5836 KiB
#include <iostream> #include <vector> #include <map> #include <set> #include <queue> #include <algorithm> #include <string> #include <cmath> #include <cstdio> #include <iomanip> #include <fstream> #include <cassert> #include <cstring> #include <unordered_set> #include <unordered_map> #include <numeric> #include <ctime> #include <bitset> #include <complex> #include <chrono> #include <random> #include <functional> using namespace std; #define int long long const int INF = 1e18 + 239; const int N = 2e5 + 7; int to[N]; int dp[N][2]; vector<pair<int, int>> g[N]; void dfs(int cur, int p) { int S = 0; int mx = -INF; for (auto [t, w] : g[cur]) { if (t != p) { to[t] = w; dfs(t, cur); S += max(dp[t][0], dp[t][1]); mx = max(mx, dp[t][0] + to[t] - max(dp[t][0], dp[t][1])); } } dp[cur][1] = S + mx + to[cur]; dp[cur][0] = S; } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; for (int i = 0; i + 1 < n; i++) { int u, v, w; cin >> u >> v >> w; u--; v--; g[u].push_back({v, w}); g[v].push_back({u, w}); } int ans = 0; for (int i = 0; i < n; i++) { dfs(i, -1); ans = max(ans, dp[i][0]); } cout << ans << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...