# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
61780 | 2018-07-26T16:40:37 Z | IvanC | Chase (CEOI17_chase) | C++17 | 369 ms | 104840 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MAXN = 1e5 + 10; const int MAXC = 1e2 + 5; vector<int> grafo[MAXN]; ll dp[MAXN][MAXC],P[MAXN],somatorio[MAXN],best; int N,C; void dfs(int v,int p){ somatorio[v] = 0; for(int i = 0;i<=C;i++) dp[v][i] = 0; for(int u : grafo[v]){ if(u == p) continue; dfs(u,v); somatorio[v] += P[u]; } for(int u : grafo[v]){ if(u == p) continue; for(int i = 1;i<=C;i++){ dp[v][i] = max(dp[v][i], max(dp[u][i], dp[u][i-1] + somatorio[v] ) ); } } } int main(){ scanf("%d %d",&N,&C); for(int i = 1;i<=N;i++){ scanf("%lld",&P[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); } int limite = N; if(N > 1000) limite = 1; for(int i = 1;i<=limite;i++){ dfs(i,-1); for(int j = 0;j<=C;j++) best = max(best,dp[i][j]); } printf("%lld\n",best); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 2680 KB | Output is correct |
2 | Correct | 4 ms | 2836 KB | Output is correct |
3 | Correct | 5 ms | 2908 KB | Output is correct |
4 | Correct | 5 ms | 2908 KB | Output is correct |
5 | Correct | 4 ms | 2952 KB | Output is correct |
6 | Correct | 5 ms | 2952 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 2680 KB | Output is correct |
2 | Correct | 4 ms | 2836 KB | Output is correct |
3 | Correct | 5 ms | 2908 KB | Output is correct |
4 | Correct | 5 ms | 2908 KB | Output is correct |
5 | Correct | 4 ms | 2952 KB | Output is correct |
6 | Correct | 5 ms | 2952 KB | Output is correct |
7 | Correct | 339 ms | 3924 KB | Output is correct |
8 | Correct | 55 ms | 3924 KB | Output is correct |
9 | Correct | 57 ms | 3924 KB | Output is correct |
10 | Correct | 369 ms | 3924 KB | Output is correct |
11 | Correct | 102 ms | 3924 KB | Output is correct |
12 | Correct | 56 ms | 3924 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 215 ms | 93676 KB | Output is correct |
2 | Correct | 271 ms | 95904 KB | Output is correct |
3 | Correct | 174 ms | 95904 KB | Output is correct |
4 | Correct | 192 ms | 96444 KB | Output is correct |
5 | Correct | 262 ms | 98572 KB | Output is correct |
6 | Correct | 260 ms | 100632 KB | Output is correct |
7 | Correct | 261 ms | 102868 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 2680 KB | Output is correct |
2 | Correct | 4 ms | 2836 KB | Output is correct |
3 | Correct | 5 ms | 2908 KB | Output is correct |
4 | Correct | 5 ms | 2908 KB | Output is correct |
5 | Correct | 4 ms | 2952 KB | Output is correct |
6 | Correct | 5 ms | 2952 KB | Output is correct |
7 | Correct | 339 ms | 3924 KB | Output is correct |
8 | Correct | 55 ms | 3924 KB | Output is correct |
9 | Correct | 57 ms | 3924 KB | Output is correct |
10 | Correct | 369 ms | 3924 KB | Output is correct |
11 | Correct | 102 ms | 3924 KB | Output is correct |
12 | Correct | 56 ms | 3924 KB | Output is correct |
13 | Correct | 215 ms | 93676 KB | Output is correct |
14 | Correct | 271 ms | 95904 KB | Output is correct |
15 | Correct | 174 ms | 95904 KB | Output is correct |
16 | Correct | 192 ms | 96444 KB | Output is correct |
17 | Correct | 262 ms | 98572 KB | Output is correct |
18 | Correct | 260 ms | 100632 KB | Output is correct |
19 | Correct | 261 ms | 102868 KB | Output is correct |
20 | Incorrect | 236 ms | 104840 KB | Output isn't correct |
21 | Halted | 0 ms | 0 KB | - |