Submission #369149

#TimeUsernameProblemLanguageResultExecution timeMemory
369149BartolMBeads and wires (APIO14_beads)C++17
13 / 100
1090 ms492 KiB
#include <bits/stdc++.h> using namespace std; #define X first #define Y second #define mp make_pair #define pb push_back typedef long long ll; typedef pair <int, int> pii; typedef pair <int, pii> pip; typedef pair <pii, int> ppi; typedef pair <ll, ll> pll; const int INF=0x3f3f3f3f; const ll MAX=(ll)INF*INF; const int N=205; int n; vector <pii> ls[N]; int dp[N][2]; int rek(int node, int fl, int par) { int ret=dp[node][fl]; if (ret!=-1) return ret; int sum0=0, ed; for (pii sus:ls[node]) { if (sus.X==par) { ed=sus.Y; continue; } sum0+=rek(sus.X, 0, node); } ret=sum0; for (pii sus:ls[node]) { if (sus.X==par) continue; if (!fl) ret=max(ret, ed+sus.Y+sum0-rek(sus.X, 0, node)+rek(sus.X, 1, node)); } return ret; } void load() { scanf("%d", &n); for (int i=0; i<n-1; ++i) { int a, b, c; scanf("%d %d %d", &a, &b, &c); ls[a].pb(mp(b, c)); ls[b].pb(mp(a, c)); } } int main() { load(); int sol=0; for (int i=1; i<=n; ++i) { memset(dp, -1, sizeof dp); sol=max(sol, rek(i, 1, 0)); } printf("%d\n", sol); return 0; }

Compilation message (stderr)

beads.cpp: In function 'void load()':
beads.cpp:44:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   44 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
beads.cpp:47:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   47 |         scanf("%d %d %d", &a, &b, &c);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
beads.cpp: In function 'int rek(int, int, int)':
beads.cpp:38:33: warning: 'ed' may be used uninitialized in this function [-Wmaybe-uninitialized]
   38 |         if (!fl) ret=max(ret, ed+sus.Y+sum0-rek(sus.X, 0, node)+rek(sus.X, 1, node));
      |                                 ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...