답안 #895361

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
895361 2023-12-29T19:34:21 Z rainboy 족보 (KOI18_family) C
17 / 100
2 ms 6748 KB
#include <stdio.h>
#include <stdlib.h>

#define N	300000

int *ej1[N], eo1[N], *ej2[N], eo2[N];

void append(int **ej, int *eo, 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 pp[N], dd[N];

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

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

		dfs1(i, j, d + 1);
	}
}

int aa[N]; char marked[N];

int dfs2(int i) {
	int o, i_, j_;

	if (eo2[i] == 0)
		aa[i] = i;
	else {
		aa[i] = -1;
		for (o = eo2[i]; o--; ) {
			int j = ej2[i][o];

			if (!dfs2(j))
				return 0;
			if (aa[i] == -1)
				aa[i] = aa[j];
			else {
				i_ = aa[i], j_ = aa[j];
				while (i_ != j_)
					if (dd[i_] > dd[j_]) {
						if (!marked[i_])
							marked[i_] = -1;
						else {
							if (marked[i_] != -1)
								return 0;
							break;
						}
						i_ = pp[i_];
					} else {
						if (!marked[j_])
							marked[j_] = -1;
						else {
							if (marked[j_] != -1)
								return 0;
							break;
						}
						j_ = pp[j_];
					}
				aa[i] = i_;
			}
		}
		for (o = eo2[i]; o--; ) {
			int j = ej2[i][o];

			j_ = aa[j];
			while (j_ != aa[i] && marked[j_] == -1)
				marked[j_] = 1, j_ = pp[j_];
		}
	}
	return 1;
}

int main() {
	int n1, n2, i, j, r1, r2;

	scanf("%d%d%*d", &n1, &n2);
	for (i = 0; i < n1; i++)
		ej1[i] = (int *) malloc(2 * sizeof *ej1[i]);
	r1 = 0;
	for (j = 0; j < n1; j++) {
		scanf("%d", &i), i--;
		if (i == -1)
			r1 = j;
		else
			append(ej1, eo1, i, j);
	}
	for (i = 0; i < n2; i++)
		ej2[i] = (int *) malloc(2 * sizeof *ej2[i]);
	r2 = 0;
	for (j = 0; j < n2; j++) {
		scanf("%d", &i), i--;
		if (i == -1)
			r2 = j;
		else
			append(ej2, eo2, i, j);
	}
	dfs1(-1, r1, 0);
	printf(dfs2(r2) ? "YES\n" : "NO\n");
	return 0;
}

Compilation message

family.c: In function 'append':
family.c:11:23: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   11 |  if (o >= 2 && (o & o - 1) == 0)
      |                     ~~^~~
family.c: In function 'main':
family.c:84:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   84 |  scanf("%d%d%*d", &n1, &n2);
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~
family.c:89:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   89 |   scanf("%d", &i), i--;
      |   ^~~~~~~~~~~~~~~
family.c:99:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   99 |   scanf("%d", &i), i--;
      |   ^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6588 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6572 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6488 KB Output is correct
9 Correct 1 ms 6568 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 2 ms 6488 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6572 KB Output is correct
18 Correct 1 ms 6576 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 1 ms 6568 KB Output is correct
22 Correct 1 ms 6492 KB Output is correct
23 Correct 1 ms 6492 KB Output is correct
24 Correct 1 ms 6492 KB Output is correct
25 Correct 1 ms 6744 KB Output is correct
26 Correct 1 ms 6492 KB Output is correct
27 Correct 1 ms 6492 KB Output is correct
28 Correct 1 ms 6492 KB Output is correct
29 Correct 1 ms 6492 KB Output is correct
30 Correct 1 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6588 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6572 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6488 KB Output is correct
9 Correct 1 ms 6568 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 2 ms 6488 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6572 KB Output is correct
18 Correct 1 ms 6576 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 1 ms 6568 KB Output is correct
22 Correct 1 ms 6492 KB Output is correct
23 Correct 1 ms 6492 KB Output is correct
24 Correct 1 ms 6492 KB Output is correct
25 Correct 1 ms 6744 KB Output is correct
26 Correct 1 ms 6492 KB Output is correct
27 Correct 1 ms 6492 KB Output is correct
28 Correct 1 ms 6492 KB Output is correct
29 Correct 1 ms 6492 KB Output is correct
30 Correct 1 ms 6492 KB Output is correct
31 Correct 1 ms 6488 KB Output is correct
32 Correct 1 ms 6492 KB Output is correct
33 Correct 1 ms 6492 KB Output is correct
34 Correct 1 ms 6492 KB Output is correct
35 Correct 1 ms 6496 KB Output is correct
36 Correct 1 ms 6492 KB Output is correct
37 Correct 1 ms 6492 KB Output is correct
38 Correct 1 ms 6576 KB Output is correct
39 Correct 1 ms 6492 KB Output is correct
40 Correct 1 ms 6492 KB Output is correct
41 Correct 1 ms 6496 KB Output is correct
42 Correct 1 ms 6492 KB Output is correct
43 Correct 1 ms 6496 KB Output is correct
44 Correct 1 ms 6492 KB Output is correct
45 Incorrect 1 ms 6748 KB Output isn't correct
46 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6588 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6572 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6488 KB Output is correct
9 Correct 1 ms 6568 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 2 ms 6488 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6572 KB Output is correct
18 Correct 1 ms 6576 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 1 ms 6568 KB Output is correct
22 Correct 1 ms 6492 KB Output is correct
23 Correct 1 ms 6492 KB Output is correct
24 Correct 1 ms 6492 KB Output is correct
25 Correct 1 ms 6744 KB Output is correct
26 Correct 1 ms 6492 KB Output is correct
27 Correct 1 ms 6492 KB Output is correct
28 Correct 1 ms 6492 KB Output is correct
29 Correct 1 ms 6492 KB Output is correct
30 Correct 1 ms 6492 KB Output is correct
31 Correct 1 ms 6488 KB Output is correct
32 Correct 1 ms 6492 KB Output is correct
33 Correct 1 ms 6492 KB Output is correct
34 Correct 1 ms 6492 KB Output is correct
35 Correct 1 ms 6496 KB Output is correct
36 Correct 1 ms 6492 KB Output is correct
37 Correct 1 ms 6492 KB Output is correct
38 Correct 1 ms 6576 KB Output is correct
39 Correct 1 ms 6492 KB Output is correct
40 Correct 1 ms 6492 KB Output is correct
41 Correct 1 ms 6496 KB Output is correct
42 Correct 1 ms 6492 KB Output is correct
43 Correct 1 ms 6496 KB Output is correct
44 Correct 1 ms 6492 KB Output is correct
45 Incorrect 1 ms 6748 KB Output isn't correct
46 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6588 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6572 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6488 KB Output is correct
9 Correct 1 ms 6568 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 2 ms 6488 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6572 KB Output is correct
18 Correct 1 ms 6576 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 1 ms 6568 KB Output is correct
22 Correct 1 ms 6492 KB Output is correct
23 Correct 1 ms 6492 KB Output is correct
24 Correct 1 ms 6492 KB Output is correct
25 Correct 1 ms 6744 KB Output is correct
26 Correct 1 ms 6492 KB Output is correct
27 Correct 1 ms 6492 KB Output is correct
28 Correct 1 ms 6492 KB Output is correct
29 Correct 1 ms 6492 KB Output is correct
30 Correct 1 ms 6492 KB Output is correct
31 Correct 1 ms 6488 KB Output is correct
32 Correct 1 ms 6492 KB Output is correct
33 Correct 1 ms 6492 KB Output is correct
34 Correct 1 ms 6492 KB Output is correct
35 Correct 1 ms 6496 KB Output is correct
36 Correct 1 ms 6492 KB Output is correct
37 Correct 1 ms 6492 KB Output is correct
38 Correct 1 ms 6576 KB Output is correct
39 Correct 1 ms 6492 KB Output is correct
40 Correct 1 ms 6492 KB Output is correct
41 Correct 1 ms 6496 KB Output is correct
42 Correct 1 ms 6492 KB Output is correct
43 Correct 1 ms 6496 KB Output is correct
44 Correct 1 ms 6492 KB Output is correct
45 Incorrect 1 ms 6748 KB Output isn't correct
46 Halted 0 ms 0 KB -