# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
259771 | 2020-08-08T13:30:15 Z | MKopchev | Chase (CEOI17_chase) | C++14 | 783 ms | 166368 KB |
#include<bits/stdc++.h> using namespace std; const int nmax=1e5+42,vmax=1e2+5; int n,put; vector<int> adj[nmax]; long long sum[nmax],inp[nmax]; long long dp[2][vmax][nmax];//0-> up, 1-> down long long outp; void dfs(int node,int par) { //cout<<"dfs "<<node<<" "<<par<<endl; //dp[0][1][node]=sum[node]; dp[1][1][node]=sum[node]; for(auto k:adj[node]) if(k!=par) { dfs(k,node); for(int j=1;j<=put;j++) { long long add_1=max(dp[0][j][k],dp[0][j-1][k]+sum[k]-inp[node]); outp=max(outp,dp[1][put-j][node]+add_1); long long add_2=max(dp[1][j][k],dp[1][j-1][k]+sum[node]-inp[k]); outp=max(outp,dp[0][put-j][node]+add_2); } for(int j=put;j>=1;j--) { long long add_1=max(dp[0][j][k],dp[0][j-1][k]+sum[k]-inp[node]); long long add_2=max(dp[1][j][k],dp[1][j-1][k]+sum[node]-inp[k]); dp[0][j][node]=max(dp[0][j][node],add_1); dp[1][j][node]=max(dp[1][j][node],add_2); } for(int j=0;j<=put;j++) { outp=max(outp,dp[0][j][node]); outp=max(outp,dp[1][j][node]); } } /* cout<<"node= "<<node<<endl; for(int j=0;j<=put;j++)cout<<dp[0][j][node]<<" ";cout<<endl; for(int j=0;j<=put;j++)cout<<dp[1][j][node]<<" ";cout<<endl; */ } int main() { scanf("%i%i",&n,&put); for(int i=1;i<=n;i++) scanf("%lld",&inp[i]); for(int i=1;i<n;i++) { int u,v; scanf("%i%i",&u,&v); adj[u].push_back(v); adj[v].push_back(u); sum[u]+=inp[v]; sum[v]+=inp[u]; } dfs(1,0); printf("%lld\n",outp); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 2688 KB | Output is correct |
2 | Correct | 2 ms | 2688 KB | Output is correct |
3 | Correct | 2 ms | 2688 KB | Output is correct |
4 | Correct | 2 ms | 2816 KB | Output is correct |
5 | Correct | 2 ms | 2688 KB | Output is correct |
6 | Correct | 2 ms | 2688 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 2688 KB | Output is correct |
2 | Correct | 2 ms | 2688 KB | Output is correct |
3 | Correct | 2 ms | 2688 KB | Output is correct |
4 | Correct | 2 ms | 2816 KB | Output is correct |
5 | Correct | 2 ms | 2688 KB | Output is correct |
6 | Correct | 2 ms | 2688 KB | Output is correct |
7 | Correct | 5 ms | 4736 KB | Output is correct |
8 | Correct | 3 ms | 2944 KB | Output is correct |
9 | Correct | 3 ms | 2816 KB | Output is correct |
10 | Correct | 7 ms | 5376 KB | Output is correct |
11 | Correct | 3 ms | 3456 KB | Output is correct |
12 | Correct | 3 ms | 3072 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 353 ms | 94688 KB | Output is correct |
2 | Correct | 346 ms | 94584 KB | Output is correct |
3 | Correct | 187 ms | 12528 KB | Output is correct |
4 | Correct | 90 ms | 11128 KB | Output is correct |
5 | Correct | 783 ms | 164600 KB | Output is correct |
6 | Correct | 679 ms | 166260 KB | Output is correct |
7 | Correct | 767 ms | 166008 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 2688 KB | Output is correct |
2 | Correct | 2 ms | 2688 KB | Output is correct |
3 | Correct | 2 ms | 2688 KB | Output is correct |
4 | Correct | 2 ms | 2816 KB | Output is correct |
5 | Correct | 2 ms | 2688 KB | Output is correct |
6 | Correct | 2 ms | 2688 KB | Output is correct |
7 | Correct | 5 ms | 4736 KB | Output is correct |
8 | Correct | 3 ms | 2944 KB | Output is correct |
9 | Correct | 3 ms | 2816 KB | Output is correct |
10 | Correct | 7 ms | 5376 KB | Output is correct |
11 | Correct | 3 ms | 3456 KB | Output is correct |
12 | Correct | 3 ms | 3072 KB | Output is correct |
13 | Correct | 353 ms | 94688 KB | Output is correct |
14 | Correct | 346 ms | 94584 KB | Output is correct |
15 | Correct | 187 ms | 12528 KB | Output is correct |
16 | Correct | 90 ms | 11128 KB | Output is correct |
17 | Correct | 783 ms | 164600 KB | Output is correct |
18 | Correct | 679 ms | 166260 KB | Output is correct |
19 | Correct | 767 ms | 166008 KB | Output is correct |
20 | Correct | 693 ms | 166368 KB | Output is correct |
21 | Correct | 89 ms | 10360 KB | Output is correct |
22 | Correct | 673 ms | 166304 KB | Output is correct |
23 | Correct | 87 ms | 11128 KB | Output is correct |
24 | Correct | 690 ms | 166284 KB | Output is correct |
25 | Correct | 175 ms | 11376 KB | Output is correct |
26 | Correct | 350 ms | 94712 KB | Output is correct |
27 | Correct | 365 ms | 94584 KB | Output is correct |