# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
887626 | rainboy | Sleepy game (innopolis2018_final_D) | C11 | 35 ms | 13556 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>
#include <string.h>
#define N 100000
int *ej[N], eo[N];
int qu[N * 2], cnt; char visited[N * 2];
int dfs1(int i) {
int o;
qu[cnt++] = i;
if (visited[i << 1 | cnt % 2]) {
cnt--;
return 0;
}
if (eo[i] == 0 && cnt % 2 == 0)
return 1;
visited[i << 1 | cnt % 2] = 1;
for (o = eo[i]; o--; ) {
int j = ej[i][o];
if (dfs1(j))
return 1;
}
cnt--;
return 0;
}
int dfs2(int i) {
int o;
if (visited[i])
return visited[i] == -1;
visited[i] = -1;
for (o = eo[i]; o--; ) {
int j = ej[i][o];
if (dfs2(j))
return 1;
}
visited[i] = 1;
return 0;
}
int main() {
int n, m, h, i, o;
scanf("%d%d", &n, &m);
for (i = 0; i < n; i++) {
scanf("%d", &eo[i]);
ej[i] = (int *) malloc(eo[i] * sizeof *ej[i]);
for (o = eo[i]; o--; )
scanf("%d", &ej[i][o]), ej[i][o]--;
}
scanf("%d", &i), i--;
if (dfs1(i)) {
printf("Win\n");
for (h = 0; h < cnt; h++)
printf("%d ", qu[h] + 1);
printf("\n");
} else {
memset(visited, 0, n * sizeof *visited);
printf(dfs2(i) ? "Draw\n" : "Lose\n");
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |