# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
199674 |
2020-02-02T17:27:41 Z |
algorithm16 |
Chase (CEOI17_chase) |
C++14 |
|
4000 ms |
51560 KB |
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
vector <int> v[100005];
int arr[100005],s[100005],dp[100005][105],n,v1;
int dfs(int x,int par,int y) {
int ret=0;
for(int j=0;j<v[x].size();j++) {
if(v[x][j]==par) continue;
ret=max(ret,dfs(v[x][j],x,y));
if(y) ret=max(ret,dfs(v[x][j],x,y-1)+s[x]-arr[par]);
}
dp[x][y]=ret;
return ret;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> v1;
for(int i=0;i<n;i++) {
cin >> arr[i];
}
for(int i=0;i<n-1;i++) {
int a,b;
cin >> a >> b;
v[a-1].push_back(b-1);
v[b-1].push_back(a-1);
}
for(int i=0;i<n;i++) {
for(int j=0;j<v[i].size();j++) {
s[i]+=arr[v[i][j]];
}
}
for(int i=0;i<=v1;i++) {
dfs(0,-1,i);
}
cout << dp[0][v1];
return 0;
}
Compilation message
chase.cpp: In function 'int dfs(int, int, int)':
chase.cpp:9:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=0;j<v[x].size();j++) {
~^~~~~~~~~~~~
chase.cpp: In function 'int main()':
chase.cpp:32:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=0;j<v[i].size();j++) {
~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
2680 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
2680 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4059 ms |
51560 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
2680 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |