# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
101589 | 2019-03-19T04:45:39 Z | jamielim | Chase (CEOI17_chase) | C++14 | 3767 ms | 176512 KB |
#include <bits/stdc++.h> using namespace std; int n,v; vector<int> adj[100005]; long long arr[100005]; long long pigeons[100005]; long long memo[100005][105][2]; long long dp(int x,int vleft,int p,int subtract){ if(memo[x][vleft][subtract]!=1000000000000000010)return memo[x][vleft][subtract]; if(vleft==0)return memo[x][0][subtract]=(subtract?-arr[x]:0); if(adj[x].size()==0)return memo[x][vleft][subtract]=pigeons[x]-(subtract?arr[x]:0); long long ans=0; for(int i=0;i<(int)adj[x].size();i++){ if(adj[x][i]==p)continue; ans=max(ans,max(dp(adj[x][i],vleft,x,0),dp(adj[x][i],vleft-1,x,1)+pigeons[x]-(subtract?arr[x]:0))); } return memo[x][vleft][subtract]=ans; } int main(){ scanf("%d%d",&n,&v); for(int i=0;i<n;i++){ scanf("%d",&arr[i]); } int a,b; for(int i=0;i<n-1;i++){ scanf("%d%d",&a,&b); a--; b--; adj[a].push_back(b); adj[b].push_back(a); } for(int i=0;i<n;i++){ pigeons[i]=0; for(int j=0;j<(int)adj[i].size();j++){ pigeons[i]+=arr[adj[i][j]]; } } if(n<=1000){ long long ans=0; for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ for(int k=0;k<=v;k++){ memo[j][k][0]=1000000000000000010; memo[j][k][1]=1000000000000000010; } } ans=max(ans,dp(i,v,-1,0)); } printf("%lld",ans); return 0; } for(int i=0;i<n;i++){ for(int j=0;j<=v;j++){ memo[i][j][0]=1000000000000000010; memo[i][j][1]=1000000000000000010; } } long long ans=dp(0,v,-1,0); for(int i=0;i<50000000/n/v;i++){ ans=max(ans,dp(rand()%n,v,-1,0)); } printf("%lld",ans); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 4 ms | 2688 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 4 ms | 2688 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 3767 ms | 176512 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 4 ms | 2688 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |