Submission #310432

# Submission time Handle Problem Language Result Execution time Memory
310432 2020-10-06T22:47:07 Z pedroslrey Chase (CEOI17_chase) C++17
30 / 100
276 ms 98680 KB
#include <bits/stdc++.h>

using namespace std;
using lli = long long int;

const int MAXN = 100010;
const int MAXM = 110;
 
#define debug(args...) //fprintf(stderr, args);

int n, m;
lli ps[MAXN];
lli dp[MAXN][MAXM];
vector<int> graph[MAXN];
 
void dfs(int v, int p) {
	lli sum = 0;
 
	for (int u: graph[v]) {
		if (u == p) continue;
 
		sum +=ps[u];
		dfs(u, v);
	}
 
	for (int k = 0; k <= m; k++) {
		dp[v][k] = 0;
		for (int u: graph[v]) {
			if (u == p)	continue;
 
			dp[v][k] = max(dp[v][k], dp[u][k]);
			if (k)	dp[v][k] = max(dp[v][k], dp[u][k - 1] + sum);
		}
	}

	debug("dp[%d][%d] = %d\n", v, m, dp[v][m]);
}
 
int main() {
	scanf("%d %d", &n, &m);
 
	for (int i = 1; i <= n; ++i)
		scanf("%lld", &ps[i]);
 
	for (int i = 0; i < n-1; ++i) {
		int u, v;
		scanf("%d %d", &u, &v);
		graph[u].push_back(v);
		graph[v].push_back(u);
	}	
 
	lli ans = 0;

	for (int i = 1; i <= 1; ++i) {
		dfs(i, i);
		debug("OI\n");

		for (int j = 1; j <= n; ++j)
			ans = max(ans, dp[j][m]);
	}
	printf("%lld\n", ans);
}

Compilation message

chase.cpp: In function 'int main()':
chase.cpp:40:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   40 |  scanf("%d %d", &n, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~~
chase.cpp:43:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   43 |   scanf("%lld", &ps[i]);
      |   ~~~~~^~~~~~~~~~~~~~~~
chase.cpp:47:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   47 |   scanf("%d %d", &u, &v);
      |   ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2688 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2688 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 183 ms 96572 KB Output is correct
2 Correct 181 ms 98680 KB Output is correct
3 Correct 276 ms 95472 KB Output is correct
4 Correct 138 ms 94840 KB Output is correct
5 Correct 193 ms 94880 KB Output is correct
6 Correct 198 ms 95008 KB Output is correct
7 Correct 195 ms 94840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2688 KB Output isn't correct
2 Halted 0 ms 0 KB -