Submission #544730

# Submission time Handle Problem Language Result Execution time Memory
544730 2022-04-02T16:14:03 Z rainboy Political Development (BOI17_politicaldevelopment) C
100 / 100
80 ms 6264 KB
/* https://codeforces.com/blog/entry/51740?#comment-356870 (koosaga) */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define N	50000
#define K	10

int *ej[N], eo[N], qu[K + 1][N], cnt[K + 1], dd[N], ans, k_;

void solve(int k) {
	int h;

	if (k + cnt[k] < ans)
		return;
	if (k == k_) {
		printf("%d\n", k_);
		exit(0);
	}
	if (ans < k)
		ans = k;
	for (h = 0; h < cnt[k]; h++) {
		int i = qu[k][h], o;

		cnt[k + 1] = 0;
		for (o = 0; o < eo[i]; o++) {
			int j = ej[i][o];

			if (dd[j] == k)
				dd[j]++, qu[k + 1][cnt[k + 1]++] = j;
		}
		solve(k + 1);
		for (o = 0; o < eo[i]; o++) {
			int j = ej[i][o];

			if (dd[j] == k + 1)
				dd[j]--;
		}
	}
}

int main() {
	int n, i, j, head;

	scanf("%d%d", &n, &k_);
	for (i = 0; i < n; i++) {
		int d;

		scanf("%d", &d), dd[i] = d;
		ej[i] = (int *) malloc((eo[i] = d) * sizeof *ej[i]);
		while (d--) {
			scanf("%d", &j);
			ej[i][d] = j;
		}
	}
	head = 0;
	for (i = 0; i < n; i++)
		if (dd[i] <= k_)
			qu[0][head + cnt[0]++] = i;
	while (cnt[0]) {
		int o, d;

		i = qu[0][cnt[0]--, head++], dd[i] = -1;
		d = 0;
		for (o = 0; o < eo[i]; o++) {
			int j = ej[i][o];

			if (dd[j] >= 0) {
				ej[i][d++] = j;
				if (--dd[j] == k_)
					qu[0][head + cnt[0]++] = j;
			}
		}
		eo[i] = d;
	}
	memset(dd, 0, n * sizeof *dd);
	cnt[0] = n;
	solve(0);
	printf("%d\n", ans);
	return 0;
}

Compilation message

politicaldevelopment.c: In function 'main':
politicaldevelopment.c:45:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |  scanf("%d%d", &n, &k_);
      |  ^~~~~~~~~~~~~~~~~~~~~~
politicaldevelopment.c:49:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |   scanf("%d", &d), dd[i] = d;
      |   ^~~~~~~~~~~~~~~
politicaldevelopment.c:52:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |    scanf("%d", &j);
      |    ^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 2 ms 560 KB Output is correct
4 Correct 2 ms 596 KB Output is correct
5 Correct 2 ms 564 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
7 Correct 2 ms 564 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 2 ms 560 KB Output is correct
4 Correct 2 ms 596 KB Output is correct
5 Correct 2 ms 564 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
7 Correct 2 ms 564 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 2 ms 596 KB Output is correct
12 Correct 2 ms 596 KB Output is correct
13 Correct 1 ms 296 KB Output is correct
14 Correct 2 ms 564 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 544 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 2 ms 596 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 2 ms 596 KB Output is correct
21 Correct 1 ms 596 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 2 ms 532 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 3 ms 596 KB Output is correct
26 Correct 3 ms 564 KB Output is correct
27 Correct 3 ms 596 KB Output is correct
28 Correct 2 ms 596 KB Output is correct
29 Correct 2 ms 596 KB Output is correct
30 Correct 3 ms 596 KB Output is correct
31 Correct 3 ms 596 KB Output is correct
32 Correct 3 ms 596 KB Output is correct
33 Correct 3 ms 536 KB Output is correct
34 Correct 3 ms 564 KB Output is correct
35 Correct 3 ms 376 KB Output is correct
36 Correct 2 ms 468 KB Output is correct
37 Correct 2 ms 468 KB Output is correct
38 Correct 1 ms 308 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 4 ms 652 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 4 ms 596 KB Output is correct
43 Correct 4 ms 692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 264 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 292 KB Output is correct
9 Correct 1 ms 296 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 80 ms 6168 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 74 ms 6264 KB Output is correct
14 Correct 1 ms 292 KB Output is correct
15 Correct 71 ms 6216 KB Output is correct
16 Correct 66 ms 6168 KB Output is correct
17 Correct 74 ms 6204 KB Output is correct
18 Correct 63 ms 6184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 2 ms 560 KB Output is correct
4 Correct 2 ms 596 KB Output is correct
5 Correct 2 ms 564 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
7 Correct 2 ms 564 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 2 ms 596 KB Output is correct
12 Correct 2 ms 596 KB Output is correct
13 Correct 1 ms 296 KB Output is correct
14 Correct 2 ms 564 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 544 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 2 ms 596 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 2 ms 596 KB Output is correct
21 Correct 1 ms 596 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 2 ms 532 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 3 ms 596 KB Output is correct
26 Correct 3 ms 564 KB Output is correct
27 Correct 3 ms 596 KB Output is correct
28 Correct 2 ms 596 KB Output is correct
29 Correct 2 ms 596 KB Output is correct
30 Correct 3 ms 596 KB Output is correct
31 Correct 3 ms 596 KB Output is correct
32 Correct 3 ms 596 KB Output is correct
33 Correct 3 ms 536 KB Output is correct
34 Correct 3 ms 564 KB Output is correct
35 Correct 3 ms 376 KB Output is correct
36 Correct 2 ms 468 KB Output is correct
37 Correct 2 ms 468 KB Output is correct
38 Correct 1 ms 308 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 4 ms 652 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 4 ms 596 KB Output is correct
43 Correct 4 ms 692 KB Output is correct
44 Correct 7 ms 852 KB Output is correct
45 Correct 1 ms 212 KB Output is correct
46 Correct 4 ms 696 KB Output is correct
47 Correct 7 ms 724 KB Output is correct
48 Correct 4 ms 596 KB Output is correct
49 Correct 7 ms 724 KB Output is correct
50 Correct 6 ms 724 KB Output is correct
51 Correct 11 ms 1200 KB Output is correct
52 Correct 2 ms 596 KB Output is correct
53 Correct 11 ms 1164 KB Output is correct
54 Correct 13 ms 1236 KB Output is correct
55 Correct 3 ms 564 KB Output is correct
56 Correct 2 ms 628 KB Output is correct
57 Correct 1 ms 468 KB Output is correct
58 Correct 11 ms 1236 KB Output is correct
59 Correct 4 ms 568 KB Output is correct
60 Correct 3 ms 596 KB Output is correct
61 Correct 4 ms 596 KB Output is correct
62 Correct 3 ms 596 KB Output is correct
63 Correct 6 ms 852 KB Output is correct
64 Correct 6 ms 740 KB Output is correct
65 Correct 4 ms 596 KB Output is correct
66 Correct 4 ms 596 KB Output is correct
67 Correct 7 ms 824 KB Output is correct
68 Correct 6 ms 852 KB Output is correct
69 Correct 4 ms 564 KB Output is correct
70 Correct 6 ms 788 KB Output is correct
71 Correct 7 ms 852 KB Output is correct
72 Correct 7 ms 820 KB Output is correct
73 Correct 3 ms 540 KB Output is correct
74 Correct 6 ms 724 KB Output is correct
75 Correct 7 ms 808 KB Output is correct
76 Correct 5 ms 724 KB Output is correct
77 Correct 9 ms 948 KB Output is correct
78 Correct 3 ms 564 KB Output is correct
79 Correct 5 ms 596 KB Output is correct
80 Correct 5 ms 692 KB Output is correct
81 Correct 11 ms 944 KB Output is correct
82 Correct 1 ms 340 KB Output is correct
83 Correct 5 ms 596 KB Output is correct
84 Correct 7 ms 852 KB Output is correct
85 Correct 1 ms 360 KB Output is correct
86 Correct 6 ms 852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 2 ms 560 KB Output is correct
4 Correct 2 ms 596 KB Output is correct
5 Correct 2 ms 564 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
7 Correct 2 ms 564 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 2 ms 596 KB Output is correct
12 Correct 2 ms 596 KB Output is correct
13 Correct 1 ms 296 KB Output is correct
14 Correct 2 ms 564 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 544 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 2 ms 596 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 2 ms 596 KB Output is correct
21 Correct 1 ms 596 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 2 ms 532 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 3 ms 596 KB Output is correct
26 Correct 3 ms 564 KB Output is correct
27 Correct 3 ms 596 KB Output is correct
28 Correct 2 ms 596 KB Output is correct
29 Correct 2 ms 596 KB Output is correct
30 Correct 3 ms 596 KB Output is correct
31 Correct 3 ms 596 KB Output is correct
32 Correct 3 ms 596 KB Output is correct
33 Correct 3 ms 536 KB Output is correct
34 Correct 3 ms 564 KB Output is correct
35 Correct 3 ms 376 KB Output is correct
36 Correct 2 ms 468 KB Output is correct
37 Correct 2 ms 468 KB Output is correct
38 Correct 1 ms 308 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 4 ms 652 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 4 ms 596 KB Output is correct
43 Correct 4 ms 692 KB Output is correct
44 Correct 1 ms 212 KB Output is correct
45 Correct 50 ms 4876 KB Output is correct
46 Correct 30 ms 3792 KB Output is correct
47 Correct 58 ms 4992 KB Output is correct
48 Correct 51 ms 4960 KB Output is correct
49 Correct 19 ms 3588 KB Output is correct
50 Correct 56 ms 5968 KB Output is correct
51 Correct 70 ms 4940 KB Output is correct
52 Correct 24 ms 3644 KB Output is correct
53 Correct 19 ms 3660 KB Output is correct
54 Correct 8 ms 2864 KB Output is correct
55 Correct 58 ms 5904 KB Output is correct
56 Correct 19 ms 3148 KB Output is correct
57 Correct 21 ms 3668 KB Output is correct
58 Correct 40 ms 3772 KB Output is correct
59 Correct 14 ms 3180 KB Output is correct
60 Correct 14 ms 3176 KB Output is correct
61 Correct 27 ms 3760 KB Output is correct
62 Correct 20 ms 3412 KB Output is correct
63 Correct 35 ms 3912 KB Output is correct
64 Correct 14 ms 3120 KB Output is correct
65 Correct 39 ms 4312 KB Output is correct
66 Correct 24 ms 3400 KB Output is correct
67 Correct 41 ms 3912 KB Output is correct
68 Correct 36 ms 4140 KB Output is correct
69 Correct 34 ms 4240 KB Output is correct
70 Correct 22 ms 3420 KB Output is correct
71 Correct 37 ms 4224 KB Output is correct
72 Correct 33 ms 3944 KB Output is correct
73 Correct 53 ms 4404 KB Output is correct
74 Correct 28 ms 3384 KB Output is correct
75 Correct 22 ms 2172 KB Output is correct
76 Correct 32 ms 3888 KB Output is correct
77 Correct 54 ms 4396 KB Output is correct
78 Correct 25 ms 2360 KB Output is correct
79 Correct 22 ms 2160 KB Output is correct
80 Correct 9 ms 1200 KB Output is correct
81 Correct 32 ms 2260 KB Output is correct
82 Correct 40 ms 4004 KB Output is correct
83 Correct 11 ms 1236 KB Output is correct
84 Correct 36 ms 4016 KB Output is correct