# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
478883 | rainboy | Wand (COCI19_wand) | C11 | 29 ms | 4804 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |