# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
311610 | 2020-10-10T18:53:48 Z | bigg | Chase (CEOI17_chase) | C++14 | 315 ms | 99544 KB |
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int MAXN = 1e5 + 10; const int MAXK = 110; ll dp[MAXN][MAXK]; ll s[MAXN], a[MAXN]; int crum; vector<int> grafo[MAXN]; void dfs(int x, int p){ for(int i = 0; i <= crum; i++) dp[x][i] = 0; for(int i = 0; i < grafo[x].size(); i++){ int viz = grafo[x][i]; if(viz == p) continue; dfs(viz, x); for(int k = 1; k <= crum; k++){ dp[x][k] = max(dp[viz][k], dp[x][k]); dp[x][k] = max(dp[x][k], dp[viz][k-1] + s[x] - a[p]); } } } int n; int main(){ scanf("%d %d", &n, &crum); if(crum == 0){ printf("0\n" ); return 0; } for(int i = 1; i <= n; i++) scanf("%lld", &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); s[u] += a[v]; s[v] += a[u]; } ll ans = 0; if(n <= 1000){ for(int i = 1; i <= n; i++){ dfs(i, 0); ans = max(ans, dp[i][crum]); } }else{ dfs(1,0); ans = dp[1][crum]; } printf("%lld\n",ans ); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 2688 KB | Output is correct |
2 | Correct | 2 ms | 2688 KB | Output is correct |
3 | Correct | 2 ms | 2688 KB | Output is correct |
4 | Correct | 2 ms | 2688 KB | Output is correct |
5 | Correct | 2 ms | 2688 KB | Output is correct |
6 | Correct | 2 ms | 2688 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 2688 KB | Output is correct |
2 | Correct | 2 ms | 2688 KB | Output is correct |
3 | Correct | 2 ms | 2688 KB | Output is correct |
4 | Correct | 2 ms | 2688 KB | Output is correct |
5 | Correct | 2 ms | 2688 KB | Output is correct |
6 | Correct | 2 ms | 2688 KB | Output is correct |
7 | Correct | 295 ms | 3584 KB | Output is correct |
8 | Correct | 38 ms | 3584 KB | Output is correct |
9 | Correct | 25 ms | 3584 KB | Output is correct |
10 | Correct | 315 ms | 3584 KB | Output is correct |
11 | Correct | 130 ms | 3584 KB | Output is correct |
12 | Correct | 74 ms | 3584 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 182 ms | 99544 KB | Output is correct |
2 | Correct | 176 ms | 99448 KB | Output is correct |
3 | Correct | 122 ms | 95984 KB | Output is correct |
4 | Correct | 139 ms | 95608 KB | Output is correct |
5 | Correct | 191 ms | 95680 KB | Output is correct |
6 | Correct | 190 ms | 95736 KB | Output is correct |
7 | Correct | 190 ms | 95608 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 2688 KB | Output is correct |
2 | Correct | 2 ms | 2688 KB | Output is correct |
3 | Correct | 2 ms | 2688 KB | Output is correct |
4 | Correct | 2 ms | 2688 KB | Output is correct |
5 | Correct | 2 ms | 2688 KB | Output is correct |
6 | Correct | 2 ms | 2688 KB | Output is correct |
7 | Correct | 295 ms | 3584 KB | Output is correct |
8 | Correct | 38 ms | 3584 KB | Output is correct |
9 | Correct | 25 ms | 3584 KB | Output is correct |
10 | Correct | 315 ms | 3584 KB | Output is correct |
11 | Correct | 130 ms | 3584 KB | Output is correct |
12 | Correct | 74 ms | 3584 KB | Output is correct |
13 | Correct | 182 ms | 99544 KB | Output is correct |
14 | Correct | 176 ms | 99448 KB | Output is correct |
15 | Correct | 122 ms | 95984 KB | Output is correct |
16 | Correct | 139 ms | 95608 KB | Output is correct |
17 | Correct | 191 ms | 95680 KB | Output is correct |
18 | Correct | 190 ms | 95736 KB | Output is correct |
19 | Correct | 190 ms | 95608 KB | Output is correct |
20 | Incorrect | 238 ms | 95736 KB | Output isn't correct |
21 | Halted | 0 ms | 0 KB | - |