Submission #134996

#TimeUsernameProblemLanguageResultExecution timeMemory
134996arthur_nascimentoBeads and wires (APIO14_beads)C++14
0 / 100
2 ms376 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back #define maxn 1010 #define pii pair<int,int> vector<pii> L[maxn]; int dp[2][maxn]; int get(int need,int vx,int p=-1){ // fprintf(stderr,"%d %d %d\n",need,vx,p); int &r = dp[need][vx]; if(r+1) return r; r = 0; int l = L[vx].size(); if(need == 0){ for(int i=0;i<l;i++) for(int j=i+1;j<l;j++){ int A = L[vx][i].first, B = L[vx][j].first; if(A == p || B == p) continue; int s = L[vx][i].second + L[vx][j].second + get(0,A,vx) + get(0,B,vx); for(int k=0;k<l;k++){ int to = L[vx][k].first; // fprintf(stderr,"to %d\n",to); if(to != A && to != B && to != p) s += max(get(0,to,vx), get(1,to,vx) + L[vx][k].second); } r = max(r,s); } int no = 0; for(int k=0;k<l;k++){ int to = L[vx][k].first; if(to != p) no += max(get(0,to,vx), get(1,to,vx) + L[vx][k].second); } r = max(r,no); // fprintf(stderr,"dp[%d][%d]=%d\n",need,vx,r); return r; } if(L[vx].size()==1) return r=-1e8; for(int i=0;i<L[vx].size();i++){ int s = 0; if(L[vx][i].first == p) continue; s = L[vx][i].second + get(0,L[vx][i].first,vx); for(int j=0;j<l;j++){ int to = L[vx][j].first; if(to == p || i == j) continue; s += max(get(0,to,vx), get(1,to,vx) + L[vx][j].second); } r = max(r,s); } return r; } int main() { int n; scanf("%d",&n); for(int i=0;i<n-1;i++){ int a,b,c; scanf("%d%d%d",&a,&b,&c), a--, b--; L[a].pb(pii(b,c)); L[b].pb(pii(a,c)); } memset(dp,-1,sizeof(dp)); printf("%d\n",get(0,0)); }

Compilation message (stderr)

beads.cpp: In function 'int get(int, int, int)':
beads.cpp:43:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<L[vx].size();i++){
                 ~^~~~~~~~~~~~~
beads.cpp: In function 'int main()':
beads.cpp:61:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
     ~~~~~^~~~~~~~~
beads.cpp:64:38: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d",&a,&b,&c), a--, b--;
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...