# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
80158 | farukkastamonuda | Dostavljač (COCI18_dostavljac) | C++14 | 218 ms | 2988 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |