# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
104444 | 2019-04-06T20:59:27 Z | luciocf | Chase (CEOI17_chase) | C++14 | 273 ms | 95480 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]; ll soma[maxn]; ll dp[maxn][maxk]; vector<int> grafo[maxn]; void dfs(int u, int p) { ll x = soma[u]-1ll*a[p]; for (int i = 1; i <= k; i++) dp[u][i] = 0; for (int i = 1; i <= k; i++) { dp[u][i] = dp[p][i]; dp[u][i] = max(dp[u][i], x+dp[p][i-1]); } for (auto v: grafo[u]) if (v != p) dfs(v, u); } 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]; ll ans = 0; if (n > 1000) { dfs(1, 0); for (int i = 1; i <= n; i++) ans = max(ans, dp[i][k]); printf("%lld\n", ans); return 0; } for (int i = 1; i <= n; i++) { dfs(i, 0); for (int i = 1; i <= n; i++) ans = max(ans, dp[i][k]); } 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 | Correct | 4 ms | 2688 KB | Output is correct |
6 | Correct | 4 ms | 2688 KB | Output is correct |
# | 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 | Correct | 4 ms | 2688 KB | Output is correct |
6 | Correct | 4 ms | 2688 KB | Output is correct |
7 | Correct | 273 ms | 3584 KB | Output is correct |
8 | Correct | 32 ms | 3584 KB | Output is correct |
9 | Correct | 22 ms | 3584 KB | Output is correct |
10 | Correct | 247 ms | 3648 KB | Output is correct |
11 | Correct | 103 ms | 3704 KB | Output is correct |
12 | Correct | 50 ms | 3584 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 208 ms | 95480 KB | Output is correct |
2 | Correct | 197 ms | 95376 KB | Output is correct |
3 | Correct | 142 ms | 93492 KB | Output is correct |
4 | Correct | 160 ms | 93172 KB | Output is correct |
5 | Correct | 220 ms | 93200 KB | Output is correct |
6 | Correct | 223 ms | 93176 KB | Output is correct |
7 | Correct | 210 ms | 93176 KB | Output is correct |
# | 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 | Correct | 4 ms | 2688 KB | Output is correct |
6 | Correct | 4 ms | 2688 KB | Output is correct |
7 | Correct | 273 ms | 3584 KB | Output is correct |
8 | Correct | 32 ms | 3584 KB | Output is correct |
9 | Correct | 22 ms | 3584 KB | Output is correct |
10 | Correct | 247 ms | 3648 KB | Output is correct |
11 | Correct | 103 ms | 3704 KB | Output is correct |
12 | Correct | 50 ms | 3584 KB | Output is correct |
13 | Correct | 208 ms | 95480 KB | Output is correct |
14 | Correct | 197 ms | 95376 KB | Output is correct |
15 | Correct | 142 ms | 93492 KB | Output is correct |
16 | Correct | 160 ms | 93172 KB | Output is correct |
17 | Correct | 220 ms | 93200 KB | Output is correct |
18 | Correct | 223 ms | 93176 KB | Output is correct |
19 | Correct | 210 ms | 93176 KB | Output is correct |
20 | Incorrect | 229 ms | 95296 KB | Output isn't correct |
21 | Halted | 0 ms | 0 KB | - |