Submission #48296

#TimeUsernameProblemLanguageResultExecution timeMemory
48296octopusesBeads and wires (APIO14_beads)C++17
0 / 100
7 ms4992 KiB
#include <bits/stdc++.h> #define ll long long #define fr first #define sc second #define M (ll)(3e17) using namespace std; const int N = 200020; vector < pair < int, int > > G[N]; int n; int A[N], B[N]; void go(int v, int p = 0) { int mx1 = -100, mx2 = -100, child = 0, tot = 0, par = -2e9; for(int i = 0; i < G[v].size(); ++ i) { int to = G[v][i].first; if(to == p) { par = G[v][i].second; continue; } go(to, v); tot += A[to]; int now = B[to] - A[to] + G[v][i].second; if(now > mx1) { mx2 = mx1; mx1 = now; } else if(now > mx2) mx2 = now; child ++; } A[v] = B[v] = tot; if(child > 1) B[v] = max(tot + mx1 + mx2, B[v]); A[v] = max(B[v], A[v]); for(int i = 0; i < G[v].size(); ++ i) { int to = G[v][i].first; if(to == p) continue; A[v] = max(A[v], tot - A[to] + B[to] + par + G[v][i].second); } } int main() { scanf("%d", &n); for(int i = 1; i < n; ++ i) { int x, y, val; scanf("%d %d %d", &x, &y, &val); G[x].push_back({y, val}); G[y].push_back({x, val}); } go(1); printf("%d\n", A[1]); }

Compilation message (stderr)

beads.cpp: In function 'void go(int, int)':
beads.cpp:18:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0; i < G[v].size(); ++ i)
                  ~~^~~~~~~~~~~~~
beads.cpp:43:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0; i < G[v].size(); ++ i)
                  ~~^~~~~~~~~~~~~
beads.cpp: In function 'int main()':
beads.cpp:54:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &n);
   ~~~~~^~~~~~~~~~
beads.cpp:58:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %d", &x, &y, &val);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...