Submission #908136

#TimeUsernameProblemLanguageResultExecution timeMemory
908136duckindogBeads and wires (APIO14_beads)C++14
28 / 100
1018 ms8792 KiB
// from duckindog wth depression #include<bits/stdc++.h> using namespace std; #define int long long const int N = 2e5 + 10; int n; vector<pair<int, int>> ad[N]; int f[2][N]; void dfs(int u, int pre = 0) { int all = -1e15, none = -1e15; for (auto duck : ad[u]) { int v, w; tie(v, w) = duck; if (v == pre) continue; if (all == -1e15) all = 0; dfs(v, u); int best = max(f[1][v] + w, f[0][v]); all += best; none = max(none, f[0][v] + w - best); } f[0][u] = max(0ll, all); f[1][u] = all + none; } int32_t main() { cin.tie(0)->sync_with_stdio(0); if (fopen("duck.inp", "r")) { freopen("duck.inp", "r", stdin); freopen("duck.out", "w", stdout); } cin >> n; for (int i = 1; i < n; ++i) { int u, v, w; cin >> u >> v >> w; ad[u].push_back({v, w}); ad[v].push_back({u, w}); } int answer = 0; for (int i = 1; i <= n; ++i) { dfs(i); answer = max(answer, *max_element(f[0] + 1, f[0] + n + 1)); } cout << answer; }

Compilation message (stderr)

beads.cpp: In function 'int32_t main()':
beads.cpp:36:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |     freopen("duck.inp", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
beads.cpp:37:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |     freopen("duck.out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...