# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1047254 | sleepntsheep | Newspapers (CEOI21_newspapers) | C11 | 1 ms | 604 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 1005
int eo[N], *eh[N];
void pus(int i, int j) {
int o = eo[i]++;
if (!o) eh[i] = (int*)malloc(2 * sizeof **eh);
else if (0 == (o & o - 1)) eh[i] = (int*)realloc(eh[i], 2 * o * sizeof **eh);
eh[i][o] = j;
}
int n, m, col[N];
int dfs(int u, int p) {
col[u] = 1;
for (int v, j = 0; j < eo[u]; ++j) if ((v = eh[u][j]) != p) {
if (col[v])
return 1;
if (dfs(v, u))
return 1;
}
return 0;
}
int main() {
scanf("%d%d", &n, &m);
for (int u, v, i = 0; i < m; ++i)
scanf("%d%d", &u, &v), pus(u, v), pus(v, u);
for (int i = 1; i <= n; ++i)
if (!col[i] && dfs(i, i)) {
puts("NO");
return 0;
}
puts("YES");
puts("1\n1");
}
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... |