# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
57969 |
2018-07-16T14:53:26 Z |
IvanC |
Chase (CEOI17_chase) |
C++17 |
|
4000 ms |
355892 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] - 2*vetor[v] );
dp[v][i][1][0] = max(dp[v][i][1][0], dp[u][i-1][0][1] + tamanho[v] - 2*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 |
4 ms |
2680 KB |
Output is correct |
2 |
Incorrect |
4 ms |
2792 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2680 KB |
Output is correct |
2 |
Incorrect |
4 ms |
2792 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4024 ms |
355892 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2680 KB |
Output is correct |
2 |
Incorrect |
4 ms |
2792 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |