# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
949047 | rainboy | 작은 사이클들 (YDX13_smallcycles) | C11 | 41 ms | 13904 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
#define M 100000
int min(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 ta[N], tb[N], sz[N], ans;
void dfs(int p, int i) {
static int t;
int o;
ta[i] = tb[i] = ++t;
sz[i] = 1;
for (o = eo[i]; o--; ) {
int j = ej[i][o];
if (j != p) {
if (!ta[j]) {
dfs(i, j);
if (tb[j] == ta[j])
sz[i] += sz[j];
else
ans += (sz[j] - 1) / 2, tb[i] = min(tb[i], tb[j]);
} else
tb[i] = min(tb[i], ta[j]);
}
}
}
int main() {
int n, m, h, i, j;
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--;
append(i, j), append(j, i);
}
dfs(-1, 0);
ans += (sz[0] - 1) / 2;
printf("%d\n", ans);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |