답안 #478883

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
478883 2021-10-08T18:53:38 Z rainboy Wand (COCI19_wand) C
63 / 70
29 ms 4804 KB
#include <stdio.h>
#include <stdlib.h>

#define N	100000

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;
}

char visited[N + 1];

void dfs(int i) {
	int o;

	if (visited[i])
		return;
	visited[i] = 1;
	for (o = eo[i]; o--; ) {
		int j = ej[i][o];

		dfs(j);
	}
}

int main() {
	int n, m, i, j, o;

	scanf("%d%d", &n, &m);
	for (i = 0; i < n; i++)
		ej[i] = (int *) malloc(2 * sizeof *ej[i]);
	while (m--) {
		scanf("%d%d", &j, &i), i--, j--;
		append(i, j);
	}
	for (o = eo[0]; o--; ) {
		j = ej[0][o];
		dfs(j);
	}
	for (i = 0; i < n; i++)
		visited[i] += '0';
	printf("%s\n", visited);
	return 0;
}

Compilation message

wand.c: In function 'append':
wand.c:11:23: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   11 |  if (o >= 2 && (o & o - 1) == 0)
      |                     ~~^~~
wand.c: In function 'main':
wand.c:34:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |  scanf("%d%d", &n, &m);
      |  ^~~~~~~~~~~~~~~~~~~~~
wand.c:38:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |   scanf("%d%d", &j, &i), i--, j--;
      |   ^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 26 ms 4688 KB Output is correct
4 Correct 26 ms 4620 KB Output is correct
5 Correct 28 ms 4448 KB Output is correct
6 Correct 26 ms 4336 KB Output is correct
7 Correct 24 ms 4432 KB Output is correct
8 Correct 27 ms 4684 KB Output is correct
9 Incorrect 29 ms 4744 KB Output isn't correct
10 Correct 27 ms 4804 KB Output is correct