Submission #35789

# Submission time Handle Problem Language Result Execution time Memory
35789 2017-11-29T15:21:52 Z ainta Chase (CEOI17_chase) C++14
100 / 100
316 ms 188392 KB
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
int n, K, X[101000];
long long S[101000], D1[101000][110], D2[101000][110], T1[110], T2[110], Res;
vector<int>E[101000];
void DFS(int a, int pp) {
	int i, x, j, k;
	D1[a][1] = S[a];
	for (i = 0; i < E[a].size(); i++) {
		x = E[a][i];
		if (x == pp)continue;
		DFS(x, a);
		for (j = 1; j <= K; j++) {
			long long d1 = max(D1[x][j], D1[x][j - 1] + S[a] - X[x]), d2 = max(D2[x][j], D2[x][j - 1] + S[x] - X[a]);
			T1[j] = d1, T2[j] = d2;
			if (j != K) {
				Res = max(Res, max(D1[a][K - j] + d2, D2[a][K - j] + d1));
				Res = max(Res, D2[x][j] + S[a]);
			}
		}
		for (j = 1; j <= K; j++) {
			D1[a][j] = max(D1[a][j], T1[j]);
			D2[a][j] = max(D2[a][j], T2[j]);
			Res = max(Res, D1[a][j]);
		}
	}
}
int main() {
	int i, a, b;
	scanf("%d%d", &n, &K);
	for (i = 1; i <= n; i++) {
		scanf("%d", &X[i]);
	}
	for (i = 1; i < n; i++) {
		scanf("%d%d", &a, &b);
		E[a].push_back(b);
		E[b].push_back(a);
		S[a] += X[b], S[b] += X[a];
	}
	if (!K) {
		printf("0\n");
		return 0;
	}
	DFS(1, 0);
	printf("%lld\n", Res);
}

Compilation message

chase.cpp: In function 'void DFS(int, int)':
chase.cpp:11:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (i = 0; i < E[a].size(); i++) {
                ^
chase.cpp:9:15: warning: unused variable 'k' [-Wunused-variable]
  int i, x, j, k;
               ^
chase.cpp: In function 'int main()':
chase.cpp:32:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &K);
                       ^
chase.cpp:34:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &X[i]);
                     ^
chase.cpp:37:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &a, &b);
                        ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 178312 KB Output is correct
2 Correct 0 ms 178312 KB Output is correct
3 Correct 0 ms 178312 KB Output is correct
4 Correct 0 ms 178312 KB Output is correct
5 Correct 0 ms 178312 KB Output is correct
6 Correct 0 ms 178312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 178312 KB Output is correct
2 Correct 0 ms 178312 KB Output is correct
3 Correct 0 ms 178312 KB Output is correct
4 Correct 0 ms 178312 KB Output is correct
5 Correct 0 ms 178312 KB Output is correct
6 Correct 0 ms 178312 KB Output is correct
7 Correct 0 ms 178312 KB Output is correct
8 Correct 3 ms 178312 KB Output is correct
9 Correct 0 ms 178312 KB Output is correct
10 Correct 3 ms 178312 KB Output is correct
11 Correct 0 ms 178312 KB Output is correct
12 Correct 3 ms 178312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 226 ms 188328 KB Output is correct
2 Correct 266 ms 188292 KB Output is correct
3 Correct 169 ms 182028 KB Output is correct
4 Correct 149 ms 181612 KB Output is correct
5 Correct 263 ms 181612 KB Output is correct
6 Correct 236 ms 181612 KB Output is correct
7 Correct 289 ms 181612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 178312 KB Output is correct
2 Correct 0 ms 178312 KB Output is correct
3 Correct 0 ms 178312 KB Output is correct
4 Correct 0 ms 178312 KB Output is correct
5 Correct 0 ms 178312 KB Output is correct
6 Correct 0 ms 178312 KB Output is correct
7 Correct 0 ms 178312 KB Output is correct
8 Correct 3 ms 178312 KB Output is correct
9 Correct 0 ms 178312 KB Output is correct
10 Correct 3 ms 178312 KB Output is correct
11 Correct 0 ms 178312 KB Output is correct
12 Correct 3 ms 178312 KB Output is correct
13 Correct 226 ms 188328 KB Output is correct
14 Correct 266 ms 188292 KB Output is correct
15 Correct 169 ms 182028 KB Output is correct
16 Correct 149 ms 181612 KB Output is correct
17 Correct 263 ms 181612 KB Output is correct
18 Correct 236 ms 181612 KB Output is correct
19 Correct 289 ms 181612 KB Output is correct
20 Correct 316 ms 181612 KB Output is correct
21 Correct 109 ms 181612 KB Output is correct
22 Correct 296 ms 181612 KB Output is correct
23 Correct 149 ms 181612 KB Output is correct
24 Correct 256 ms 181612 KB Output is correct
25 Correct 166 ms 182028 KB Output is correct
26 Correct 263 ms 188392 KB Output is correct
27 Correct 253 ms 188388 KB Output is correct