# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
899958 |
2024-01-07T11:07:26 Z |
alexdd |
Chase (CEOI17_chase) |
C++17 |
|
1037 ms |
262192 KB |
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,k,rez;
int p[100005];
int dpup[100005][105];
int dpdown[100005][105][2];
vector<int> con[100005];
void dfs(int nod, int par)
{
int sump=0;
for(auto adj:con[nod])
{
if(adj!=par)
{
dfs(adj,nod);
sump += p[adj];
}
}
for(int i=1;i<=k;i++)
{
dpup[nod][i]=0;
dpdown[nod][i][0]=0;
dpdown[nod][i][1]=0;
}
dpup[nod][1] = sump + p[par];
for(auto adj:con[nod])
{
if(adj!=par)
{
for(int i=1;i<=k;i++)
{
rez = max(rez, dpup[adj][i] + dpdown[nod][k-i][0]);
rez = max(rez, dpup[adj][i] + dpdown[nod][k-i][1] - p[adj]);
}
for(int i=1;i<=k;i++)
{
dpup[nod][i] = max(dpup[nod][i], dpup[adj][i]);
dpup[nod][i] = max(dpup[nod][i], dpup[adj][i-1] + sump + p[par] - p[adj]);
dpdown[nod][i][0] = max(dpdown[nod][i][0], dpdown[adj][i][0]);
dpdown[nod][i][0] = max(dpdown[nod][i][0], dpdown[adj][i][1] - p[nod]);
dpdown[nod][i][1] = max(dpdown[nod][i][1], dpdown[adj][i-1][0] + sump + p[par]);
dpdown[nod][i][1] = max(dpdown[nod][i][1], dpdown[adj][i-1][1] - p[nod] + sump + p[par]);
dpdown[nod][i][0] = max(dpdown[nod][i][0], dpdown[nod][i-1][0]);
dpdown[nod][i][1] = max(dpdown[nod][i][1], dpdown[nod][i-1][1]);
}
}
}
for(int i=1;i<=k;i++)
{
dpup[nod][i] = max(dpup[nod][i], dpup[nod][i-1]);
rez = max(rez, dpup[nod][i]);
dpdown[nod][i][0] = max(dpdown[nod][i][0], dpdown[nod][i-1][0]);
dpdown[nod][i][1] = max(dpdown[nod][i][1], dpdown[nod][i-1][1]);
rez = max(rez, dpdown[nod][i][0]);
rez = max(rez, dpdown[nod][i][1]);
}
}
signed main()
{
cin>>n>>k;
for(int i=1;i<=n;i++)
cin>>p[i];
int a,b;
for(int i=1;i<n;i++)
{
cin>>a>>b;
con[a].push_back(b);
con[b].push_back(a);
}
if(n<=1000)
{
for(int i=2;i<=n;i++)
dfs(i,0);
}
dfs(1,0);
cout<<rez;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6748 KB |
Output is correct |
2 |
Correct |
1 ms |
6748 KB |
Output is correct |
3 |
Correct |
1 ms |
6748 KB |
Output is correct |
4 |
Correct |
2 ms |
6748 KB |
Output is correct |
5 |
Correct |
1 ms |
6748 KB |
Output is correct |
6 |
Correct |
1 ms |
6748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6748 KB |
Output is correct |
2 |
Correct |
1 ms |
6748 KB |
Output is correct |
3 |
Correct |
1 ms |
6748 KB |
Output is correct |
4 |
Correct |
2 ms |
6748 KB |
Output is correct |
5 |
Correct |
1 ms |
6748 KB |
Output is correct |
6 |
Correct |
1 ms |
6748 KB |
Output is correct |
7 |
Correct |
1035 ms |
6748 KB |
Output is correct |
8 |
Correct |
72 ms |
6992 KB |
Output is correct |
9 |
Correct |
72 ms |
6744 KB |
Output is correct |
10 |
Correct |
1037 ms |
6796 KB |
Output is correct |
11 |
Correct |
328 ms |
6796 KB |
Output is correct |
12 |
Correct |
116 ms |
6796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
257 ms |
260080 KB |
Output is correct |
2 |
Correct |
232 ms |
261976 KB |
Output is correct |
3 |
Correct |
198 ms |
256340 KB |
Output is correct |
4 |
Correct |
115 ms |
255876 KB |
Output is correct |
5 |
Correct |
249 ms |
255864 KB |
Output is correct |
6 |
Correct |
252 ms |
255764 KB |
Output is correct |
7 |
Correct |
250 ms |
255972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6748 KB |
Output is correct |
2 |
Correct |
1 ms |
6748 KB |
Output is correct |
3 |
Correct |
1 ms |
6748 KB |
Output is correct |
4 |
Correct |
2 ms |
6748 KB |
Output is correct |
5 |
Correct |
1 ms |
6748 KB |
Output is correct |
6 |
Correct |
1 ms |
6748 KB |
Output is correct |
7 |
Correct |
1035 ms |
6748 KB |
Output is correct |
8 |
Correct |
72 ms |
6992 KB |
Output is correct |
9 |
Correct |
72 ms |
6744 KB |
Output is correct |
10 |
Correct |
1037 ms |
6796 KB |
Output is correct |
11 |
Correct |
328 ms |
6796 KB |
Output is correct |
12 |
Correct |
116 ms |
6796 KB |
Output is correct |
13 |
Correct |
257 ms |
260080 KB |
Output is correct |
14 |
Correct |
232 ms |
261976 KB |
Output is correct |
15 |
Correct |
198 ms |
256340 KB |
Output is correct |
16 |
Correct |
115 ms |
255876 KB |
Output is correct |
17 |
Correct |
249 ms |
255864 KB |
Output is correct |
18 |
Correct |
252 ms |
255764 KB |
Output is correct |
19 |
Correct |
250 ms |
255972 KB |
Output is correct |
20 |
Correct |
254 ms |
256336 KB |
Output is correct |
21 |
Correct |
89 ms |
93776 KB |
Output is correct |
22 |
Correct |
250 ms |
255804 KB |
Output is correct |
23 |
Correct |
115 ms |
255828 KB |
Output is correct |
24 |
Correct |
260 ms |
255876 KB |
Output is correct |
25 |
Correct |
192 ms |
255684 KB |
Output is correct |
26 |
Correct |
232 ms |
262192 KB |
Output is correct |
27 |
Correct |
232 ms |
262172 KB |
Output is correct |