# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
309578 | 2020-10-03T20:18:34 Z | Kenzo_1114 | Chase (CEOI17_chase) | C++14 | 495 ms | 1400 KB |
#include<bits/stdc++.h> using namespace std; const int MAXN = 1010; const int MAXM = 110; int n, m; long long int p[MAXN], dp[MAXN][MAXM]; vector<int> graph[MAXN]; void dfs(int v, int par) { long long int sumP = 0; for(int i = 0; i < graph[v].size(); i++) { int u = graph[v][i]; if(u == par) continue; sumP += p[u]; dfs(u, v); } for(int k = 0; k <= m; k++) { dp[v][k] = 0; for(int i = 0; i < graph[v].size(); i++) { int u = graph[v][i]; if(u == par) continue; dp[v][k] = max(dp[v][k], dp[u][k]); if(k) dp[v][k] = max(dp[v][k], dp[u][k - 1] + sumP); } } } int main () { scanf("%d %d", &n, &m); for(int i = 1; i <= n; i++) scanf("%lld", &p[i]); for(int i = 0, u, v; i < n - 1; i++) { scanf("%d %d", &u, &v); graph[u].push_back(v); graph[v].push_back(u); } long long int ans = 0; if(n <= 1000) { for(int i = 1; i <= n; i++) { dfs(i, i); for(int j = 1; j <= n; j++) ans = max(ans, dp[j][m]); } } else { dfs(1, 1); for(int j = 1; j <= n; j++) ans = max(ans, dp[j][m]); } printf("%lld\n", ans); } /* 12 2 2 3 3 8 1 5 6 7 8 3 5 4 2 1 2 7 3 4 4 7 7 6 5 6 6 8 6 9 7 10 10 11 10 12 */
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 0 ms | 384 KB | Output is correct |
3 | Correct | 1 ms | 384 KB | Output is correct |
4 | Correct | 0 ms | 384 KB | Output is correct |
5 | Correct | 1 ms | 384 KB | Output is correct |
6 | Correct | 1 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 0 ms | 384 KB | Output is correct |
3 | Correct | 1 ms | 384 KB | Output is correct |
4 | Correct | 0 ms | 384 KB | Output is correct |
5 | Correct | 1 ms | 384 KB | Output is correct |
6 | Correct | 1 ms | 384 KB | Output is correct |
7 | Correct | 481 ms | 1280 KB | Output is correct |
8 | Correct | 52 ms | 1280 KB | Output is correct |
9 | Correct | 51 ms | 1296 KB | Output is correct |
10 | Correct | 495 ms | 1400 KB | Output is correct |
11 | Correct | 179 ms | 1280 KB | Output is correct |
12 | Correct | 75 ms | 1280 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 384 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 0 ms | 384 KB | Output is correct |
3 | Correct | 1 ms | 384 KB | Output is correct |
4 | Correct | 0 ms | 384 KB | Output is correct |
5 | Correct | 1 ms | 384 KB | Output is correct |
6 | Correct | 1 ms | 384 KB | Output is correct |
7 | Correct | 481 ms | 1280 KB | Output is correct |
8 | Correct | 52 ms | 1280 KB | Output is correct |
9 | Correct | 51 ms | 1296 KB | Output is correct |
10 | Correct | 495 ms | 1400 KB | Output is correct |
11 | Correct | 179 ms | 1280 KB | Output is correct |
12 | Correct | 75 ms | 1280 KB | Output is correct |
13 | Incorrect | 1 ms | 384 KB | Output isn't correct |
14 | Halted | 0 ms | 0 KB | - |