Submission #80158

#TimeUsernameProblemLanguageResultExecution timeMemory
80158farukkastamonudaDostavljač (COCI18_dostavljac)C++14
140 / 140
218 ms2988 KiB
#include <bits/stdc++.h> #define fi first #define se second #define lo long long #define inf 1000000000 #define md 1000000007 #define li 505 #define mp make_pair #define pb push_back using namespace std; int n,T,x,y,dp[li][li],A[li],en[li][li]; vector<int> v[li]; void dfs(int node,int ata){ for(int i=0;i<(int)v[node].size();i++){ int go=v[node][i]; if(go==ata) continue; dfs(go,node); } for(int i=0;i<(int)v[node].size();i++){ int go=v[node][i]; if(go==ata) continue; for(int k=T;k>=3;k--){ for(int j=1;j+2<=k;j++){ en[node][k]=max(en[node][k],en[node][k-j-2]+dp[go][j]); } } for(int k=T;k>=2;k--){ for(int j=1;j+1<=k;j++){ en[node][k]=max(en[node][k],dp[node][k-j-1]+en[go][j]); } } for(int k=T;k>=3;k--){ for(int j=1;j+2<=k;j++){ dp[node][k]=max(dp[node][k],dp[node][k-j-2]+dp[go][j]); } } } for(int j=T;j>=1;j--){ dp[node][j]=max(dp[node][j],dp[node][j-1]+A[node]); en[node][j]=max(en[node][j],en[node][j-1]+A[node]); } } int main(){ scanf("%d %d",&n,&T); for(int i=1;i<=n;i++) scanf("%d",&A[i]); for(int i=1;i<n;i++){ scanf("%d %d",&x,&y); v[x].pb(y); v[y].pb(x); } dfs(1,0); printf("%d\n",en[1][T]); return 0; }

Compilation message (stderr)

dostavljac.cpp: In function 'int main()':
dostavljac.cpp:44:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d",&n,&T);
  ~~~~~^~~~~~~~~~~~~~~
dostavljac.cpp:45:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=1;i<=n;i++) scanf("%d",&A[i]);
                        ~~~~~^~~~~~~~~~~~
dostavljac.cpp:47:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d",&x,&y);
   ~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...