# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
960929 |
2024-04-11T09:02:26 Z |
Ghetto |
Chase (CEOI17_chase) |
C++17 |
|
541 ms |
100668 KB |
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
using lint = long long;
const int MAX_N = 1e5 + 5, MAX_K = 1e2 + 5;
int n, k;
lint val[MAX_N];
vector<int> adj[MAX_N], adj_ind[MAX_N]; // adj_ind[u][i] = ind of adj list u is for adj[u][i]
int par[MAX_N];
vector<int> children[MAX_N];
void init() {
for (int i = 1; i <= n; i++) children[i].push_back(0);
}
int child_ind[MAX_N];
int n_inds, ind[MAX_N], rev_ind[MAX_N];
void dfs(int u) {
ind[u] = ++n_inds;
rev_ind[ind[u]] = u;
for (int v : adj[u]) {
if (ind[v]) continue;
par[v] = u;
children[u].push_back(v);
child_ind[v] = children[u].size() - 1;
dfs(v);
}
}
lint val_sum[MAX_N];
void precomp() {
dfs(1);
for (int i = 1; i <= n; i++)
for (int j : adj[i]) val_sum[i] += val[j];
}
lint dp1[MAX_N][MAX_K];
int main() {
// freopen("chase.in", "r", stdin);
cin >> n >> k;
for (int i = 1; i <= n; i++) cin >> val[i];
for (int i = 1; i < n; i++) {
int u, v; cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
precomp();
for (int c = 1; c <= k; c++) {
for (int i = n; i >= 1; i--) {
int u = rev_ind[i];
lint leave = 0;
for (int v : children[u])
if (v != 0) leave = max(leave, dp1[v][c]);
lint take = 0;
for (int v : children[u])
if (v != 0) take = max(take, dp1[v][c - 1]);
take += val_sum[u] - val[par[u]];
dp1[u][c] = max(take, leave);
}
}
cout << dp1[1][k] << endl;
// for (int c = 1; c <= k; c++) {
// for (int i = 1; i <= n; i++) {
// int u = rev_ind[i];
// }
// }
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
9560 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
9560 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
353 ms |
100668 KB |
Output is correct |
2 |
Correct |
358 ms |
100432 KB |
Output is correct |
3 |
Correct |
257 ms |
96840 KB |
Output is correct |
4 |
Correct |
103 ms |
97620 KB |
Output is correct |
5 |
Correct |
541 ms |
97644 KB |
Output is correct |
6 |
Correct |
514 ms |
97640 KB |
Output is correct |
7 |
Correct |
523 ms |
97640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
9560 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |