# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
61779 | 2018-07-26T16:39:33 Z | IvanC | Chase (CEOI17_chase) | C++17 | 4000 ms | 96120 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); } for(int i = 1;i<=N;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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 2680 KB | Output is correct |
2 | Correct | 5 ms | 2680 KB | Output is correct |
3 | Correct | 6 ms | 2832 KB | Output is correct |
4 | Correct | 7 ms | 2912 KB | Output is correct |
5 | Correct | 5 ms | 2912 KB | Output is correct |
6 | Correct | 4 ms | 2912 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 2680 KB | Output is correct |
2 | Correct | 5 ms | 2680 KB | Output is correct |
3 | Correct | 6 ms | 2832 KB | Output is correct |
4 | Correct | 7 ms | 2912 KB | Output is correct |
5 | Correct | 5 ms | 2912 KB | Output is correct |
6 | Correct | 4 ms | 2912 KB | Output is correct |
7 | Correct | 342 ms | 3900 KB | Output is correct |
8 | Correct | 59 ms | 3900 KB | Output is correct |
9 | Correct | 64 ms | 3900 KB | Output is correct |
10 | Correct | 350 ms | 3960 KB | Output is correct |
11 | Correct | 124 ms | 4068 KB | Output is correct |
12 | Correct | 59 ms | 4104 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 4103 ms | 96120 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 2680 KB | Output is correct |
2 | Correct | 5 ms | 2680 KB | Output is correct |
3 | Correct | 6 ms | 2832 KB | Output is correct |
4 | Correct | 7 ms | 2912 KB | Output is correct |
5 | Correct | 5 ms | 2912 KB | Output is correct |
6 | Correct | 4 ms | 2912 KB | Output is correct |
7 | Correct | 342 ms | 3900 KB | Output is correct |
8 | Correct | 59 ms | 3900 KB | Output is correct |
9 | Correct | 64 ms | 3900 KB | Output is correct |
10 | Correct | 350 ms | 3960 KB | Output is correct |
11 | Correct | 124 ms | 4068 KB | Output is correct |
12 | Correct | 59 ms | 4104 KB | Output is correct |
13 | Execution timed out | 4103 ms | 96120 KB | Time limit exceeded |
14 | Halted | 0 ms | 0 KB | - |