# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
57973 |
2018-07-16T14:58:11 Z |
IvanC |
Chase (CEOI17_chase) |
C++17 |
|
4000 ms |
357996 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 1e5 + 10;
const int MAXC = 110;
vector<int> grafo[MAXN];
ll dp[MAXN][MAXC][2][2],vetor[MAXN],tamanho[MAXN],melhor_diferenca;
int N,C;
void solve(int v,int p){
for(int i = 0;i<=C;i++){
dp[v][i][0][0] = 0;
dp[v][i][0][1] = 0;
dp[v][i][1][0] = 0;
dp[v][i][1][1] = 0;
}
tamanho[v] = vetor[v];
for(int u : grafo[v]) tamanho[v] += vetor[u];
dp[v][1][1][0] = tamanho[v] - vetor[v];
for(int u : grafo[v]){
if(u == p) continue;
solve(u,v);
for(int i = 0;i<=C;i++){
if(i != 0){
dp[v][i][1][0] = max(dp[v][i][1][0], dp[u][i-1][0][0] + tamanho[v] - vetor[v] );
dp[v][i][1][0] = max(dp[v][i][1][0], dp[u][i-1][0][1] + tamanho[v] - vetor[v] - vetor[u] );
dp[v][i][1][1] = max(dp[v][i][1][1], dp[u][i-1][1][0] + tamanho[v] - vetor[v] - vetor[u] );
dp[v][i][1][1] = max(dp[v][i][1][1], dp[u][i-1][1][1] + tamanho[v] - vetor[v] - vetor[u] );
}
dp[v][i][0][0] = max(dp[v][i][0][0],dp[u][i][0][0]);
dp[v][i][0][1] = max(dp[v][i][0][1], max(dp[u][i][1][1],dp[u][i][1][0]) );
}
}
for(int i = 0;i<=C;i++){
melhor_diferenca = max(melhor_diferenca,max(dp[v][i][0][0],dp[v][i][1][0]));
melhor_diferenca = max(melhor_diferenca,max(dp[v][i][0][1],dp[v][i][1][1]));
}
}
int main(){
cin >> N >> C;
for(int i = 1;i<=N;i++){
cin >> vetor[i];
}
for(int i = 1;i<N;i++){
int u,v;
cin >> u >> v;
grafo[u].push_back(v);
grafo[v].push_back(u);
}
for(int i = 1;i<=N;i++) solve(i,-1);
cout << melhor_diferenca << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
2680 KB |
Output is correct |
2 |
Correct |
4 ms |
2792 KB |
Output is correct |
3 |
Correct |
4 ms |
2824 KB |
Output is correct |
4 |
Correct |
6 ms |
2880 KB |
Output is correct |
5 |
Correct |
6 ms |
2880 KB |
Output is correct |
6 |
Correct |
5 ms |
2880 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
2680 KB |
Output is correct |
2 |
Correct |
4 ms |
2792 KB |
Output is correct |
3 |
Correct |
4 ms |
2824 KB |
Output is correct |
4 |
Correct |
6 ms |
2880 KB |
Output is correct |
5 |
Correct |
6 ms |
2880 KB |
Output is correct |
6 |
Correct |
5 ms |
2880 KB |
Output is correct |
7 |
Incorrect |
1402 ms |
6512 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4032 ms |
357996 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 |
4 ms |
2792 KB |
Output is correct |
3 |
Correct |
4 ms |
2824 KB |
Output is correct |
4 |
Correct |
6 ms |
2880 KB |
Output is correct |
5 |
Correct |
6 ms |
2880 KB |
Output is correct |
6 |
Correct |
5 ms |
2880 KB |
Output is correct |
7 |
Incorrect |
1402 ms |
6512 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |