# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
468951 |
2021-08-30T09:27:36 Z |
wdjpng |
Chase (CEOI17_chase) |
C++17 |
|
845 ms |
96892 KB |
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#define int long long
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
int n,v;
vector<int>p;
vector<vector<int>>mem;
vector<vector<int>>E;
int dfs(int pos, int bc, int parent)
{
if(mem[pos][bc]!=-1) return mem[pos][bc];
if(bc==0) return 0;
int sum = 0;
for(int w : E[pos])
{
if(w==parent) continue;
sum+=p[w];
}
int maxx = 0;
for(int w : E[pos])
{
if(w==parent) continue;
maxx=max(maxx, dfs(w, bc, pos));
maxx=max(maxx, dfs(w, bc-1, pos) + sum);
}
return mem[pos][bc] = maxx;
}
signed main()
{
cin>>n>>v;
p.resize(n+1);
rep(i, n) cin>>p[i+1];
E.resize(n+1);
mem.assign(n+1, vector<int>(v+1, -1));
rep(i,n-1)
{
int a,b;
cin>>a>>b;
E[a].push_back(b);
E[b].push_back(a);
}
cout<<dfs(1, v, -1)<<"\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
645 ms |
96892 KB |
Output is correct |
2 |
Correct |
583 ms |
96864 KB |
Output is correct |
3 |
Correct |
177 ms |
91600 KB |
Output is correct |
4 |
Correct |
153 ms |
14616 KB |
Output is correct |
5 |
Correct |
845 ms |
91428 KB |
Output is correct |
6 |
Correct |
685 ms |
91444 KB |
Output is correct |
7 |
Correct |
786 ms |
91440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |