# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
104458 | 2019-04-06T23:15:59 Z | luciocf | Chase (CEOI17_chase) | C++14 | 506 ms | 204816 KB |
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5+10; const int maxk = 110; typedef long long ll; int n, k; int a[maxn]; int ant[maxn][maxk], ant_child[maxk]; ll soma[maxn]; ll d[2][maxn][maxk], ans; vector<int> grafo[maxn]; void dfs(int u, int p) { for (auto v: grafo[u]) { if (v == p) continue; dfs(v, u); for (int i = 1; i <= k; i++) { ll x = soma[v]-1ll*a[u]; ll D = max(d[0][v][i], x+d[0][v][i-1]); if (D > d[0][u][i]) d[1][u][i] = d[0][u][i], d[0][u][i] = D; else if (D > d[1][u][i]) d[1][u][i] = D; } } } void rotate(int u, int p) { ans = max({ans, d[0][u][k], soma[u]+d[0][u][k-1]}); for (auto v: grafo[u]) { if (v == p) continue; for (int i = 1; i <= k; i++) ant_child[i] = d[0][v][i]; for (int i = 1; i <= k; i++) { ant[u][i] = d[0][u][i]; ll x = soma[v]-1ll*a[u]; ll D = max(d[0][v][i], x+ant_child[i-1]); if (d[0][u][i] == D) d[0][u][i] = d[1][u][i]; x = soma[u]-1ll*a[v]; D = max(d[0][u][i], x+d[0][u][i-1]); if (D > d[0][v][i]) d[1][v][i] = d[0][v][i], d[0][v][i] = D; else if (D > d[1][v][i]) d[1][v][i] = D; } rotate(v, u); for (int i = 1; i <= k; i++) d[0][u][i] = ant[u][i]; } } int main(void) { scanf("%d %d", &n, &k); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); for (int i = 1; i < n; i++) { int u, v; scanf("%d %d", &u, &v); grafo[u].push_back(v); grafo[v].push_back(u); } for (int i = 1; i <= n; i++) for (auto v: grafo[i]) soma[i] += 1ll*a[v]; dfs(1, 0); rotate(1, 0); printf("%lld\n", ans); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 2688 KB | Output is correct |
2 | Correct | 4 ms | 2688 KB | Output is correct |
3 | Correct | 4 ms | 2688 KB | Output is correct |
4 | Correct | 4 ms | 2688 KB | Output is correct |
5 | Incorrect | 5 ms | 2688 KB | Output isn't correct |
6 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 2688 KB | Output is correct |
2 | Correct | 4 ms | 2688 KB | Output is correct |
3 | Correct | 4 ms | 2688 KB | Output is correct |
4 | Correct | 4 ms | 2688 KB | Output is correct |
5 | Incorrect | 5 ms | 2688 KB | Output isn't correct |
6 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 506 ms | 204816 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 2688 KB | Output is correct |
2 | Correct | 4 ms | 2688 KB | Output is correct |
3 | Correct | 4 ms | 2688 KB | Output is correct |
4 | Correct | 4 ms | 2688 KB | Output is correct |
5 | Incorrect | 5 ms | 2688 KB | Output isn't correct |
6 | Halted | 0 ms | 0 KB | - |