# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
104443 | 2019-04-06T20:58:04 Z | luciocf | Chase (CEOI17_chase) | C++14 | 4000 ms | 97656 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] = 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++) { memset(dp, 0, sizeof dp); dfs(i, 0); for (int i = 1; i <= n; i++) ans = max(ans, dp[i][k]); } printf("%lld\n", ans); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 253 ms | 88824 KB | Output is correct |
2 | Correct | 252 ms | 88824 KB | Output is correct |
3 | Correct | 270 ms | 88824 KB | Output is correct |
4 | Correct | 239 ms | 88952 KB | Output is correct |
5 | Correct | 272 ms | 88824 KB | Output is correct |
6 | Correct | 237 ms | 88952 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 253 ms | 88824 KB | Output is correct |
2 | Correct | 252 ms | 88824 KB | Output is correct |
3 | Correct | 270 ms | 88824 KB | Output is correct |
4 | Correct | 239 ms | 88952 KB | Output is correct |
5 | Correct | 272 ms | 88824 KB | Output is correct |
6 | Correct | 237 ms | 88952 KB | Output is correct |
7 | Execution timed out | 4082 ms | 88796 KB | Time limit exceeded |
8 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 205 ms | 97528 KB | Output is correct |
2 | Correct | 190 ms | 97656 KB | Output is correct |
3 | Correct | 128 ms | 95600 KB | Output is correct |
4 | Correct | 161 ms | 95324 KB | Output is correct |
5 | Correct | 195 ms | 95324 KB | Output is correct |
6 | Correct | 196 ms | 95364 KB | Output is correct |
7 | Correct | 173 ms | 95352 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 253 ms | 88824 KB | Output is correct |
2 | Correct | 252 ms | 88824 KB | Output is correct |
3 | Correct | 270 ms | 88824 KB | Output is correct |
4 | Correct | 239 ms | 88952 KB | Output is correct |
5 | Correct | 272 ms | 88824 KB | Output is correct |
6 | Correct | 237 ms | 88952 KB | Output is correct |
7 | Execution timed out | 4082 ms | 88796 KB | Time limit exceeded |
8 | Halted | 0 ms | 0 KB | - |