Submission #752010

#TimeUsernameProblemLanguageResultExecution timeMemory
752010boyliguanhanBeads and wires (APIO14_beads)C++17
28 / 100
1072 ms1000 KiB
#include<bits/stdc++.h> #pragma GCC optimize(2) using namespace std; int dp[10010][2]; vector<pair<int, int>> adj[10010]; void dfs(int n, int p) { dp[n][0] = 0; dp[n][1] = -1000000000; int m1=-1000000000; for(auto [i, j]: adj[n]) { if(i!=p) { dfs(i, n); int X = max(dp[i][1]+j, dp[i][0]); dp[n][0]+=X; int x = dp[i][0] + j - X; m1 = max(m1, x); } } dp[n][1]=dp[n][0]+m1; } int main() { cin.sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; for(int i = 1; i < n; i++) { int a, b, c; cin >> a >> b >> c; adj[a].push_back({b, c}); adj[b].push_back({a, c}); } int mx = 0; for(int i = 1; i <= n; i++) { dfs(i, 0); mx = max(mx, dp[i][0]); } cout << mx << '\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...