# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
939611 |
2024-03-06T15:07:32 Z |
vjudge1 |
Chase (CEOI17_chase) |
C++17 |
|
235 ms |
94036 KB |
#include <bits/stdc++.h>
#define int long long
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
using namespace std;
const int N=1e5+5;
vector <int> g[N];
int fr_sum[N],x[N];
int dp[N][105];
int n,k;
void dfs(int v,int p){
for(auto to : g[v]){
if(to!=p){
for(int i=1;i<=k;i++)dp[to][i]=max(dp[v][i],dp[v][i-1]+fr_sum[to]-x[v]);
dfs(to,v);
}
}
}
signed main(){
ios_base::sync_with_stdio();
cin.tie(0);cout.tie(0);
cin>>n>>k;
for(int i=1;i<=n;i++)cin>>x[i];
for(int i=1;i<n;i++){
int u,v;
cin>>u>>v;
g[u].pb(v);
g[v].pb(u);
fr_sum[v]+=x[u];
fr_sum[u]+=x[v];
}
int ans=0;
if(n<=1000){
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
for(int t=0;t<=k;t++){
dp[j][t]=0;
}
}
for(int j=1;j<=k;j++){
dp[i][j]=fr_sum[i];
}
dfs(i,0);
for(int j=1;j<=n;j++){
for(int t=0;t<=k;t++){
ans=max(ans,dp[j][t]);
}
}
}
cout<<ans<<"\n";
return 0;
}
for(int j=1;j<=k;j++){
dp[1][j]=fr_sum[1];
}
dfs(1,0);
for(int j=1;j<=n;j++){
for(int t=0;t<=k;t++){
ans=max(ans,dp[j][t]);
}
}
cout<<ans<<"\n";
}
/*
12 2
2 3 3 8 1 5 6 7 8 3 5 4
2 1
2 7
3 4
4 7
7 6
5 6
6 8
6 9
7 10
10 11
10 12
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6236 KB |
Output is correct |
2 |
Correct |
2 ms |
6244 KB |
Output is correct |
3 |
Correct |
2 ms |
6236 KB |
Output is correct |
4 |
Correct |
2 ms |
6236 KB |
Output is correct |
5 |
Correct |
2 ms |
6236 KB |
Output is correct |
6 |
Correct |
2 ms |
6232 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6236 KB |
Output is correct |
2 |
Correct |
2 ms |
6244 KB |
Output is correct |
3 |
Correct |
2 ms |
6236 KB |
Output is correct |
4 |
Correct |
2 ms |
6236 KB |
Output is correct |
5 |
Correct |
2 ms |
6236 KB |
Output is correct |
6 |
Correct |
2 ms |
6232 KB |
Output is correct |
7 |
Correct |
217 ms |
8612 KB |
Output is correct |
8 |
Correct |
24 ms |
8536 KB |
Output is correct |
9 |
Correct |
20 ms |
8608 KB |
Output is correct |
10 |
Correct |
235 ms |
8580 KB |
Output is correct |
11 |
Correct |
79 ms |
8540 KB |
Output is correct |
12 |
Correct |
34 ms |
8536 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
141 ms |
94036 KB |
Output is correct |
2 |
Correct |
128 ms |
94036 KB |
Output is correct |
3 |
Correct |
100 ms |
90312 KB |
Output is correct |
4 |
Correct |
97 ms |
90028 KB |
Output is correct |
5 |
Correct |
146 ms |
90080 KB |
Output is correct |
6 |
Correct |
138 ms |
90208 KB |
Output is correct |
7 |
Correct |
138 ms |
90380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6236 KB |
Output is correct |
2 |
Correct |
2 ms |
6244 KB |
Output is correct |
3 |
Correct |
2 ms |
6236 KB |
Output is correct |
4 |
Correct |
2 ms |
6236 KB |
Output is correct |
5 |
Correct |
2 ms |
6236 KB |
Output is correct |
6 |
Correct |
2 ms |
6232 KB |
Output is correct |
7 |
Correct |
217 ms |
8612 KB |
Output is correct |
8 |
Correct |
24 ms |
8536 KB |
Output is correct |
9 |
Correct |
20 ms |
8608 KB |
Output is correct |
10 |
Correct |
235 ms |
8580 KB |
Output is correct |
11 |
Correct |
79 ms |
8540 KB |
Output is correct |
12 |
Correct |
34 ms |
8536 KB |
Output is correct |
13 |
Correct |
141 ms |
94036 KB |
Output is correct |
14 |
Correct |
128 ms |
94036 KB |
Output is correct |
15 |
Correct |
100 ms |
90312 KB |
Output is correct |
16 |
Correct |
97 ms |
90028 KB |
Output is correct |
17 |
Correct |
146 ms |
90080 KB |
Output is correct |
18 |
Correct |
138 ms |
90208 KB |
Output is correct |
19 |
Correct |
138 ms |
90380 KB |
Output is correct |
20 |
Incorrect |
155 ms |
90588 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |