Submission #121640

# Submission time Handle Problem Language Result Execution time Memory
121640 2019-06-26T21:33:32 Z pamaj Chase (CEOI17_chase) C++14
0 / 100
3 ms 1280 KB
#include <bits/stdc++.h>
using namespace std;
 
#define int int64_t
 
const int maxn = 1e3 + 10;
 
int v[maxn], p[maxn], n, t, dp[maxn][110];
vector<int> G[maxn];
 
int solve(int x, int y, int num)
{
	if(dp[x][num] != -1) return dp[x][num];
	if(num == 0) return 0;
	
	int best = 0;
 
	for(auto u : G[x])
	{
		if(u == y) continue;
 
		int caso1 = solve(u, x, num);
		int caso2 = v[u] + -p[y] + solve(u, x, num - 1);
 
		best = max({best, caso1, caso2});
	}
 
 
	return dp[x][num] = best;
}
 
int32_t main()
{
	cin >> n >> t;
 
	for(int i = 1; i <= n; i++)
	{
		cin >> p[i];
	}
 
	for(int i = 0; i < n - 1; i++)
	{
		int a, b;
		cin >> a >> b;
 
		G[a].push_back(b);
		G[b].push_back(a);
	}
 
	for(int i = 1; i <= n; i++)
	{
		for(auto u : G[i])
		{
			v[i] += p[u];
		}
	}
 
	memset(dp, -1, sizeof(dp));
 
	int ans = 0;
 
	for(int i = 1; i <= n; i++)
	{
		ans = max(ans, solve(i, 0, t));
		//cout << i << " " << solve(i, i, t) << "\n";
	}
	cout << ans << "\n";
 
	for(int i = 1; i <= n; i++)
	{
		//cout << i << " " << v[i] << "\n";
	}
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1280 KB Output is correct
2 Incorrect 3 ms 1280 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1280 KB Output is correct
2 Incorrect 3 ms 1280 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1280 KB Output is correct
2 Incorrect 3 ms 1280 KB Output isn't correct
3 Halted 0 ms 0 KB -