# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
853873 |
2023-09-25T11:27:07 Z |
thanh913 |
Chase (CEOI17_chase) |
C++14 |
|
188 ms |
157496 KB |
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
using ll = long long;
const int N = 1e5+5;
//--------------------------------------
int n, k, a[100001];
vector<int> adj[100001];
ll down[100001][101], up[100001][101], ans = 0;
void dfs(int u, int par) {
ll sum = 0;
for (int v : adj[u]) sum += a[v];
up[u][1] = sum;
for (int v : adj[u]) if (v != par) {
dfs(v, u);
for (int i = 1; i <= k; i++) ans = max(ans, up[u][i] + down[v][k - i]);
for (int i = 1; i <= k; i++) {
down[u][i] = max({down[u][i], down[v][i], down[v][i-1] + sum - a[par]});
up[u][i] = max({up[u][i], up[v][i], up[v][i-1] + sum - a[v]});
}
}
memset(up[u], 0, sizeof(up[u]));
up[u][1] = sum;
reverse(adj[u].begin(), adj[u].end());
for (int v : adj[u]) if (v != par) {
for (int i = 1; i <= k; i++) ans = max(ans, up[u][i] + down[v][k-i]);
for (int i = 1; i <= k; i++)
up[u][i] = max({up[u][i], up[v][i], up[v][i-1] + sum - a[v]});
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> n >> k;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i < n; i++) {
int u, v; cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
dfs(1, 0);
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4700 KB |
Output is correct |
2 |
Correct |
1 ms |
4700 KB |
Output is correct |
3 |
Correct |
1 ms |
4796 KB |
Output is correct |
4 |
Correct |
1 ms |
4696 KB |
Output is correct |
5 |
Correct |
1 ms |
4700 KB |
Output is correct |
6 |
Correct |
1 ms |
4696 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4700 KB |
Output is correct |
2 |
Correct |
1 ms |
4700 KB |
Output is correct |
3 |
Correct |
1 ms |
4796 KB |
Output is correct |
4 |
Correct |
1 ms |
4696 KB |
Output is correct |
5 |
Correct |
1 ms |
4700 KB |
Output is correct |
6 |
Correct |
1 ms |
4696 KB |
Output is correct |
7 |
Correct |
3 ms |
7516 KB |
Output is correct |
8 |
Correct |
2 ms |
7516 KB |
Output is correct |
9 |
Correct |
2 ms |
7004 KB |
Output is correct |
10 |
Correct |
2 ms |
7516 KB |
Output is correct |
11 |
Correct |
2 ms |
7516 KB |
Output is correct |
12 |
Correct |
2 ms |
7512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
140 ms |
135148 KB |
Output is correct |
2 |
Correct |
138 ms |
135500 KB |
Output is correct |
3 |
Correct |
122 ms |
89808 KB |
Output is correct |
4 |
Correct |
165 ms |
155108 KB |
Output is correct |
5 |
Correct |
188 ms |
157496 KB |
Output is correct |
6 |
Correct |
175 ms |
157264 KB |
Output is correct |
7 |
Correct |
181 ms |
157140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4700 KB |
Output is correct |
2 |
Correct |
1 ms |
4700 KB |
Output is correct |
3 |
Correct |
1 ms |
4796 KB |
Output is correct |
4 |
Correct |
1 ms |
4696 KB |
Output is correct |
5 |
Correct |
1 ms |
4700 KB |
Output is correct |
6 |
Correct |
1 ms |
4696 KB |
Output is correct |
7 |
Correct |
3 ms |
7516 KB |
Output is correct |
8 |
Correct |
2 ms |
7516 KB |
Output is correct |
9 |
Correct |
2 ms |
7004 KB |
Output is correct |
10 |
Correct |
2 ms |
7516 KB |
Output is correct |
11 |
Correct |
2 ms |
7516 KB |
Output is correct |
12 |
Correct |
2 ms |
7512 KB |
Output is correct |
13 |
Correct |
140 ms |
135148 KB |
Output is correct |
14 |
Correct |
138 ms |
135500 KB |
Output is correct |
15 |
Correct |
122 ms |
89808 KB |
Output is correct |
16 |
Correct |
165 ms |
155108 KB |
Output is correct |
17 |
Correct |
188 ms |
157496 KB |
Output is correct |
18 |
Correct |
175 ms |
157264 KB |
Output is correct |
19 |
Correct |
181 ms |
157140 KB |
Output is correct |
20 |
Correct |
171 ms |
157264 KB |
Output is correct |
21 |
Correct |
67 ms |
90664 KB |
Output is correct |
22 |
Correct |
175 ms |
157048 KB |
Output is correct |
23 |
Correct |
100 ms |
155476 KB |
Output is correct |
24 |
Correct |
169 ms |
157264 KB |
Output is correct |
25 |
Correct |
121 ms |
89548 KB |
Output is correct |
26 |
Correct |
154 ms |
135448 KB |
Output is correct |
27 |
Correct |
150 ms |
135248 KB |
Output is correct |