답안 #762787

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
762787 2023-06-21T19:03:16 Z rainboy Bread First Search (CCO21_day2problem2) C
25 / 25
59 ms 14792 KB
#include <stdio.h>
#include <stdlib.h>

#define N	200000

int max(int a, int b) { return a > b ? a : b; }

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 main() {
	static char used[N];
	static int jj[N], kk[N], dp[N + 1], dq[N + 1];
	int n, m, h, i, j, j_, k, o, tmp;

	scanf("%d%d", &n, &m);
	for (i = 0; i < n; i++)
		ej[i] = (int *) malloc(2 * sizeof *ej[i]);
	for (h = 0; h < m; h++) {
		scanf("%d%d", &i, &j), i--, j--;
		if (i > j)
			tmp = i, i = j, j = tmp;
		append(i, j);
	}
	for (i = 0, j_ = -1, k = 0; i < n; i++) {
		if (used[i])
			k--;
		j_ = max(j_, i + 1);
		for (o = eo[i]; o--; ) {
			j = ej[i][o];
			if (!used[j])
				used[j] = 1, k++;
			j_ = max(j_, j);
		}
		jj[i] = j_, kk[i] = k;
	}
	dp[n - 1] = dq[n - 1] = 0;
	for (i = n - 2; i >= 0; i--) {
		dp[i] = kk[i] + dq[jj[i]];
		dq[i] = max(dq[i + 1], dp[i]);
	}
	printf("%d\n", n - 1 - dp[0]);
	return 0;
}

Compilation message

Main.c: In function 'append':
Main.c:13:23: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   13 |  if (o >= 2 && (o & o - 1) == 0)
      |                     ~~^~~
Main.c: In function 'main':
Main.c:23:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |  scanf("%d%d", &n, &m);
      |  ^~~~~~~~~~~~~~~~~~~~~
Main.c:27:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |   scanf("%d%d", &i, &j), i--, j--;
      |   ^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 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 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 296 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 296 KB Output is correct
10 Correct 1 ms 288 KB Output is correct
11 Correct 1 ms 296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 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 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 296 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 296 KB Output is correct
10 Correct 1 ms 288 KB Output is correct
11 Correct 1 ms 296 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 296 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 296 KB Output is correct
21 Correct 1 ms 288 KB Output is correct
22 Correct 1 ms 296 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 ms 596 KB Output is correct
25 Correct 3 ms 724 KB Output is correct
26 Correct 3 ms 724 KB Output is correct
27 Correct 3 ms 724 KB Output is correct
28 Correct 3 ms 724 KB Output is correct
29 Correct 1 ms 524 KB Output is correct
30 Correct 8 ms 1200 KB Output is correct
31 Correct 6 ms 1196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 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 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 296 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 296 KB Output is correct
10 Correct 1 ms 288 KB Output is correct
11 Correct 1 ms 296 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 296 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 296 KB Output is correct
21 Correct 1 ms 288 KB Output is correct
22 Correct 1 ms 296 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 ms 596 KB Output is correct
25 Correct 3 ms 724 KB Output is correct
26 Correct 3 ms 724 KB Output is correct
27 Correct 3 ms 724 KB Output is correct
28 Correct 3 ms 724 KB Output is correct
29 Correct 1 ms 524 KB Output is correct
30 Correct 8 ms 1200 KB Output is correct
31 Correct 6 ms 1196 KB Output is correct
32 Correct 8 ms 11220 KB Output is correct
33 Correct 9 ms 12208 KB Output is correct
34 Correct 40 ms 11724 KB Output is correct
35 Correct 46 ms 14640 KB Output is correct
36 Correct 50 ms 14780 KB Output is correct
37 Correct 55 ms 14752 KB Output is correct
38 Correct 8 ms 11732 KB Output is correct
39 Correct 10 ms 12272 KB Output is correct
40 Correct 20 ms 7428 KB Output is correct
41 Correct 46 ms 11732 KB Output is correct
42 Correct 45 ms 14784 KB Output is correct
43 Correct 59 ms 14792 KB Output is correct
44 Correct 1 ms 212 KB Output is correct
45 Correct 1 ms 284 KB Output is correct