답안 #58087

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
58087 2018-07-16T18:59:38 Z IvanC Chase (CEOI17_chase) C++17
20 / 100
4000 ms 357604 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++){
			dp[v][i][0][0] = max(dp[v][i][0][0], max(dp[u][i][0][0],dp[u][i][0][1]) );
			dp[v][i][0][1] = max(dp[v][i][0][1], max(dp[u][i][1][0],dp[u][i][1][1]) );
			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] );
			}
		}
	}
	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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 2680 KB Output is correct
2 Correct 4 ms 2680 KB Output is correct
3 Correct 5 ms 2696 KB Output is correct
4 Correct 4 ms 2868 KB Output is correct
5 Correct 4 ms 2924 KB Output is correct
6 Correct 4 ms 2924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 2680 KB Output is correct
2 Correct 4 ms 2680 KB Output is correct
3 Correct 5 ms 2696 KB Output is correct
4 Correct 4 ms 2868 KB Output is correct
5 Correct 4 ms 2924 KB Output is correct
6 Correct 4 ms 2924 KB Output is correct
7 Incorrect 1422 ms 6444 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4038 ms 357604 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 2680 KB Output is correct
2 Correct 4 ms 2680 KB Output is correct
3 Correct 5 ms 2696 KB Output is correct
4 Correct 4 ms 2868 KB Output is correct
5 Correct 4 ms 2924 KB Output is correct
6 Correct 4 ms 2924 KB Output is correct
7 Incorrect 1422 ms 6444 KB Output isn't correct
8 Halted 0 ms 0 KB -