Submission #200101

# Submission time Handle Problem Language Result Execution time Memory
200101 2020-02-05T10:39:31 Z Saboon Dostavljač (COCI18_dostavljac) C++14
14 / 140
308 ms 2168 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

const int maxn = 500 + 37;

int a[maxn];
vector<int> t[maxn];
short Time = 1, st[maxn], ft[maxn], pos[maxn];
short dis[maxn][maxn];
int dp[maxn][maxn];

void dfsdis(int v, int src, int par = -1){
	for (auto u : t[v]){
		if (u == par)
			continue;
		dis[src][u] = dis[src][v] + 1;
		dfsdis(u, src, v);
	}
}

void dfs(int v, int par = -1){
	pos[Time] = v;
	st[v] = Time ++;
	for (auto u : t[v])
		if (u != par)
			dfs(u, v);
}

int main(){
	int n, m;
	cin >> n >> m;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	for (int i = 0; i < n - 1; i++){
		int v, u;
		cin >> v >> u;
		t[v].push_back(u);
		t[u].push_back(v);
	}
	for (int i = 1; i <= n; i++)
		dfsdis(i, i);
	dfs(1);
	memset(dp, -63, sizeof dp);
	dp[1][0] = 0, dp[1][1] = a[1];
	int answer = a[1];
	for (int i = 2; i <= n; i++){
		int v = pos[i];
		for (int x = 0; x <= m; x++){
			for (int j = 1; j < i; j++){
				int u = pos[j];
				if (dis[u][v] + 1 <= x)
					dp[i][x] = max(dp[i][x], dp[j][x - dis[u][v] - 1] + a[v]);
			}
			answer = max(answer, dp[i][x]);
		}
	}
	cout << answer << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 1528 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 1528 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 1528 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 1528 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 1656 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 38 ms 1656 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 43 ms 1784 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 155 ms 2040 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 308 ms 2168 KB Output isn't correct
2 Halted 0 ms 0 KB -