# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
104463 | 2019-04-06T23:29:03 Z | luciocf | Chase (CEOI17_chase) | C++14 | 706 ms | 252524 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 d[2][maxn][maxk], ans; ll ant[maxn][maxk]; 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 D = max(d[0][v][i], d[0][v][i-1]+soma[v]-1ll*a[u]); 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) { for (int i = 1; i <= k; i++) ans = max({ans, d[0][u][i], soma[u]+d[0][u][i-1]}); for (auto v: grafo[u]) { if (v == p) continue; for (int i = 1; i <= k; i++) { ant[u][i] = d[0][u][i]; ll D = max(d[0][v][i], d[0][v][i-1]+soma[v]-1ll*a[u]); if (d[0][u][i] == D) d[0][u][i] = d[1][u][i]; } for (int i = 1; i <= k; i++) { ll D = max(d[0][u][i], d[0][u][i-1]+soma[u]-1ll*a[v]); 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
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 2688 KB | Output is correct |
2 | Correct | 4 ms | 2688 KB | Output is correct |
3 | Correct | 4 ms | 2712 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 |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 2688 KB | Output is correct |
2 | Correct | 4 ms | 2688 KB | Output is correct |
3 | Correct | 4 ms | 2712 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 | 7 ms | 4992 KB | Output is correct |
8 | Correct | 6 ms | 4992 KB | Output is correct |
9 | Correct | 7 ms | 4480 KB | Output is correct |
10 | Correct | 8 ms | 5248 KB | Output is correct |
11 | Correct | 7 ms | 5248 KB | Output is correct |
12 | Correct | 6 ms | 5120 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 530 ms | 227852 KB | Output is correct |
2 | Correct | 542 ms | 227808 KB | Output is correct |
3 | Correct | 277 ms | 179568 KB | Output is correct |
4 | Correct | 358 ms | 250028 KB | Output is correct |
5 | Correct | 696 ms | 252524 KB | Output is correct |
6 | Correct | 695 ms | 252408 KB | Output is correct |
7 | Correct | 685 ms | 252292 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 2688 KB | Output is correct |
2 | Correct | 4 ms | 2688 KB | Output is correct |
3 | Correct | 4 ms | 2712 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 | 7 ms | 4992 KB | Output is correct |
8 | Correct | 6 ms | 4992 KB | Output is correct |
9 | Correct | 7 ms | 4480 KB | Output is correct |
10 | Correct | 8 ms | 5248 KB | Output is correct |
11 | Correct | 7 ms | 5248 KB | Output is correct |
12 | Correct | 6 ms | 5120 KB | Output is correct |
13 | Correct | 530 ms | 227852 KB | Output is correct |
14 | Correct | 542 ms | 227808 KB | Output is correct |
15 | Correct | 277 ms | 179568 KB | Output is correct |
16 | Correct | 358 ms | 250028 KB | Output is correct |
17 | Correct | 696 ms | 252524 KB | Output is correct |
18 | Correct | 695 ms | 252408 KB | Output is correct |
19 | Correct | 685 ms | 252292 KB | Output is correct |
20 | Correct | 706 ms | 252352 KB | Output is correct |
21 | Correct | 123 ms | 7288 KB | Output is correct |
22 | Correct | 698 ms | 252184 KB | Output is correct |
23 | Correct | 329 ms | 250104 KB | Output is correct |
24 | Correct | 697 ms | 252500 KB | Output is correct |
25 | Correct | 276 ms | 179568 KB | Output is correct |
26 | Correct | 524 ms | 227804 KB | Output is correct |
27 | Correct | 499 ms | 227836 KB | Output is correct |