Submission #636582

# Submission time Handle Problem Language Result Execution time Memory
636582 2022-08-29T15:38:18 Z rainboy Jail (JOI22_jail) C
66 / 100
72 ms 16640 KB
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define N	120000
#define M	500

int *ej[N], eo[N];

void append(int i, int j) {
	int o = eo[i]++;

	if (o >= 2 && (o & o - 1) == 0)
		ej[i] = (int *) realloc(ej[i], o * 2 * sizeof *ej[i]);
	ej[i][o] = j;
}

int dd[N], pp[N];

void dfs1(int p, int i, int d) {
	int o;

	dd[i] = d, pp[i] = p;
	for (o = eo[i]; o--; ) {
		int j = ej[i][o];

		if (j != p)
			dfs1(i, j, d + 1);
	}
}

char aa[M][M]; int in[M];

void dfs2(int m, int h) {
	int h_;

	if (in[h])
		return;
	in[h] = -1;
	for (h_ = 0; h_ < m; h_++)
		if (aa[h][h_])
			in[h_]--, dfs2(m, h_);
}

int main() {
	int t;

	scanf("%d", &t);
	while (t--) {
		static int ii[M], jj[N];
		static char visited[N];
		int n, m, h, h_, h1, h2, i, j, line, yes;

		scanf("%d", &n);
		for (i = 0; i < n; i++)
			ej[i] = (int *) malloc(2 * sizeof *ej[i]), eo[i] = 0;
		line = 1;
		for (h = 0; h < n - 1; h++) {
			scanf("%d%d", &i, &j), i--, j--;
			if (i + 1 != j)
				line = 0;
			append(i, j), append(j, i);
		}
		dfs1(-1, 0, 0);
		if (line) {
			scanf("%d", &m);
			memset(jj, -1, n * sizeof *jj);
			while (m--) {
				scanf("%d%d", &i, &j), i--, j--;
				jj[i] = j;
			}
			yes = 1;
			for (i = 0, j = -1; i < n; i++)
				if (jj[i] != -1) {
					if (j >= jj[i]) {
						yes = 0;
						break;
					}
					j = jj[i];
				}
			printf(yes ? "Yes\n" : "No\n");
		} else {
			scanf("%d", &m);
			for (h = 0; h < m; h++)
				scanf("%d%d", &ii[h], &jj[h]), ii[h]--, jj[h]--;
			for (h = 0; h < m; h++)
				memset(aa[h], 0, m * sizeof *aa[h]);
			for (h = 0; h < m; h++) {
				i = ii[h], j = jj[h];
				memset(visited, 0, n * sizeof *visited);
				while (i != j)
					if (dd[i] > dd[j])
						visited[i] = 1, i = pp[i];
					else
						visited[j] = 1, j = pp[j];
				visited[i] = 1;
				for (h_ = 0; h_ < m; h_++)
					if (h_ != h) {
						if (visited[ii[h_]])
							aa[h_][h] = 1;
						if (visited[jj[h_]])
							aa[h][h_] = 1;
					}
			}
			memset(in, 0, m * sizeof *in);
			for (h1 = 0; h1 < m; h1++)
				for (h2 = 0; h2 < m; h2++)
					if (aa[h1][h2])
						in[h2]++;
			for (h = 0; h < m; h++)
				dfs2(m, h);
			yes = 1;
			for (h = 0; h < m; h++)
				if (in[h] > 0) {
					yes = 0;
					break;
				}
			printf(yes ? "Yes\n" : "No\n");
		}
	}
	return 0;
}

Compilation message

jail.c: In function 'append':
jail.c:13:23: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   13 |  if (o >= 2 && (o & o - 1) == 0)
      |                     ~~^~~
jail.c: In function 'main':
jail.c:48:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |  scanf("%d", &t);
      |  ^~~~~~~~~~~~~~~
jail.c:54:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |   scanf("%d", &n);
      |   ^~~~~~~~~~~~~~~
jail.c:59:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |    scanf("%d%d", &i, &j), i--, j--;
      |    ^~~~~~~~~~~~~~~~~~~~~
jail.c:66:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   66 |    scanf("%d", &m);
      |    ^~~~~~~~~~~~~~~
jail.c:69:5: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   69 |     scanf("%d%d", &i, &j), i--, j--;
      |     ^~~~~~~~~~~~~~~~~~~~~
jail.c:83:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   83 |    scanf("%d", &m);
      |    ^~~~~~~~~~~~~~~
jail.c:85:5: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   85 |     scanf("%d%d", &ii[h], &jj[h]), ii[h]--, jj[h]--;
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 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 0 ms 212 KB Output is correct
4 Correct 12 ms 2004 KB Output is correct
5 Correct 25 ms 4048 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 2 ms 448 KB Output is correct
9 Correct 29 ms 4548 KB Output is correct
10 Correct 43 ms 16200 KB Output is correct
11 Correct 9 ms 852 KB Output is correct
12 Correct 30 ms 3940 KB Output is correct
13 Correct 44 ms 16200 KB Output is correct
14 Correct 43 ms 16232 KB Output is correct
15 Correct 44 ms 16200 KB Output is correct
16 Correct 58 ms 16236 KB Output is correct
17 Correct 48 ms 16208 KB Output is correct
18 Correct 72 ms 16236 KB Output is correct
19 Correct 55 ms 16200 KB Output is correct
20 Correct 47 ms 16204 KB Output is correct
21 Correct 49 ms 16204 KB Output is correct
22 Correct 46 ms 16204 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 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 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 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 2 ms 468 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 0 ms 340 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 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 2 ms 468 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 3 ms 468 KB Output is correct
30 Correct 2 ms 468 KB Output is correct
31 Correct 3 ms 468 KB Output is correct
32 Correct 2 ms 468 KB Output is correct
33 Correct 2 ms 468 KB Output is correct
34 Correct 3 ms 468 KB Output is correct
35 Correct 3 ms 468 KB Output is correct
36 Correct 3 ms 468 KB Output is correct
37 Correct 2 ms 340 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 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 2 ms 468 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 3 ms 468 KB Output is correct
30 Correct 2 ms 468 KB Output is correct
31 Correct 3 ms 468 KB Output is correct
32 Correct 2 ms 468 KB Output is correct
33 Correct 2 ms 468 KB Output is correct
34 Correct 3 ms 468 KB Output is correct
35 Correct 3 ms 468 KB Output is correct
36 Correct 3 ms 468 KB Output is correct
37 Correct 2 ms 340 KB Output is correct
38 Correct 34 ms 4584 KB Output is correct
39 Correct 36 ms 16164 KB Output is correct
40 Correct 70 ms 5524 KB Output is correct
41 Correct 46 ms 5740 KB Output is correct
42 Correct 58 ms 6092 KB Output is correct
43 Correct 31 ms 5532 KB Output is correct
44 Correct 20 ms 1444 KB Output is correct
45 Correct 46 ms 8276 KB Output is correct
46 Correct 54 ms 8224 KB Output is correct
47 Correct 61 ms 12856 KB Output is correct
48 Correct 65 ms 12876 KB Output is correct
49 Correct 45 ms 8452 KB Output is correct
50 Correct 45 ms 8444 KB Output is correct
51 Correct 37 ms 9568 KB Output is correct
52 Correct 35 ms 9656 KB Output is correct
53 Correct 20 ms 1972 KB Output is correct
54 Correct 53 ms 8116 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 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 6 ms 868 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 35 ms 2388 KB Output is correct
14 Correct 39 ms 4992 KB Output is correct
15 Correct 35 ms 3892 KB Output is correct
16 Runtime error 59 ms 16640 KB Execution killed with signal 11
17 Halted 0 ms 0 KB -
# 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 0 ms 212 KB Output is correct
4 Correct 12 ms 2004 KB Output is correct
5 Correct 25 ms 4048 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 2 ms 448 KB Output is correct
9 Correct 29 ms 4548 KB Output is correct
10 Correct 43 ms 16200 KB Output is correct
11 Correct 9 ms 852 KB Output is correct
12 Correct 30 ms 3940 KB Output is correct
13 Correct 44 ms 16200 KB Output is correct
14 Correct 43 ms 16232 KB Output is correct
15 Correct 44 ms 16200 KB Output is correct
16 Correct 58 ms 16236 KB Output is correct
17 Correct 48 ms 16208 KB Output is correct
18 Correct 72 ms 16236 KB Output is correct
19 Correct 55 ms 16200 KB Output is correct
20 Correct 47 ms 16204 KB Output is correct
21 Correct 49 ms 16204 KB Output is correct
22 Correct 46 ms 16204 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 2 ms 468 KB Output is correct
30 Correct 2 ms 468 KB Output is correct
31 Correct 2 ms 468 KB Output is correct
32 Correct 2 ms 468 KB Output is correct
33 Correct 2 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 2 ms 468 KB Output is correct
39 Correct 2 ms 468 KB Output is correct
40 Correct 1 ms 468 KB Output is correct
41 Correct 0 ms 212 KB Output is correct
42 Correct 1 ms 468 KB Output is correct
43 Correct 1 ms 468 KB Output is correct
44 Correct 1 ms 468 KB Output is correct
45 Correct 0 ms 212 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 2 ms 468 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 1 ms 468 KB Output is correct
50 Correct 0 ms 340 KB Output is correct
51 Correct 3 ms 468 KB Output is correct
52 Correct 2 ms 468 KB Output is correct
53 Correct 3 ms 468 KB Output is correct
54 Correct 2 ms 468 KB Output is correct
55 Correct 2 ms 468 KB Output is correct
56 Correct 3 ms 468 KB Output is correct
57 Correct 3 ms 468 KB Output is correct
58 Correct 3 ms 468 KB Output is correct
59 Correct 2 ms 340 KB Output is correct
60 Correct 34 ms 4584 KB Output is correct
61 Correct 36 ms 16164 KB Output is correct
62 Correct 70 ms 5524 KB Output is correct
63 Correct 46 ms 5740 KB Output is correct
64 Correct 58 ms 6092 KB Output is correct
65 Correct 31 ms 5532 KB Output is correct
66 Correct 20 ms 1444 KB Output is correct
67 Correct 46 ms 8276 KB Output is correct
68 Correct 54 ms 8224 KB Output is correct
69 Correct 61 ms 12856 KB Output is correct
70 Correct 65 ms 12876 KB Output is correct
71 Correct 45 ms 8452 KB Output is correct
72 Correct 45 ms 8444 KB Output is correct
73 Correct 37 ms 9568 KB Output is correct
74 Correct 35 ms 9656 KB Output is correct
75 Correct 20 ms 1972 KB Output is correct
76 Correct 53 ms 8116 KB Output is correct
77 Correct 0 ms 212 KB Output is correct
78 Correct 0 ms 212 KB Output is correct
79 Correct 0 ms 212 KB Output is correct
80 Correct 0 ms 212 KB Output is correct
81 Correct 6 ms 868 KB Output is correct
82 Correct 1 ms 340 KB Output is correct
83 Correct 1 ms 340 KB Output is correct
84 Correct 0 ms 212 KB Output is correct
85 Correct 0 ms 340 KB Output is correct
86 Correct 1 ms 340 KB Output is correct
87 Correct 1 ms 340 KB Output is correct
88 Correct 2 ms 468 KB Output is correct
89 Correct 35 ms 2388 KB Output is correct
90 Correct 39 ms 4992 KB Output is correct
91 Correct 35 ms 3892 KB Output is correct
92 Runtime error 59 ms 16640 KB Execution killed with signal 11
93 Halted 0 ms 0 KB -