Submission #949047

# Submission time Handle Problem Language Result Execution time Memory
949047 2024-03-18T20:59:12 Z rainboy 작은 사이클들 (YDX13_smallcycles) C
1 / 1
41 ms 13904 KB
#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

E.c: In function 'append':
E.c:14:23: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   14 |  if (o >= 2 && (o & o - 1) == 0)
      |                     ~~^~~
E.c: In function 'main':
E.c:46:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |  scanf("%d%d", &n, &m);
      |  ^~~~~~~~~~~~~~~~~~~~~
E.c:50:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |   scanf("%d%d", &i, &j), i--, j--;
      |   ^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 424 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 23 ms 7144 KB Output is correct
9 Correct 23 ms 7152 KB Output is correct
10 Correct 16 ms 4056 KB Output is correct
11 Correct 25 ms 6744 KB Output is correct
12 Correct 23 ms 7260 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 31 ms 6776 KB Output is correct
18 Correct 21 ms 7516 KB Output is correct
19 Correct 22 ms 7516 KB Output is correct
20 Correct 10 ms 3932 KB Output is correct
21 Correct 17 ms 6828 KB Output is correct
22 Correct 19 ms 7168 KB Output is correct
23 Correct 0 ms 344 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 860 KB Output is correct
27 Correct 3 ms 1204 KB Output is correct
28 Correct 26 ms 11612 KB Output is correct
29 Correct 29 ms 12260 KB Output is correct
30 Correct 22 ms 5740 KB Output is correct
31 Correct 41 ms 12088 KB Output is correct
32 Correct 26 ms 13904 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 2 ms 860 KB Output is correct
37 Correct 18 ms 6584 KB Output is correct
38 Correct 20 ms 7504 KB Output is correct
39 Correct 26 ms 7508 KB Output is correct
40 Correct 10 ms 3984 KB Output is correct
41 Correct 18 ms 6992 KB Output is correct
42 Correct 20 ms 7676 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 1 ms 348 KB Output is correct
46 Correct 2 ms 860 KB Output is correct
47 Correct 4 ms 1628 KB Output is correct
48 Correct 23 ms 7788 KB Output is correct
49 Correct 24 ms 8204 KB Output is correct
50 Correct 17 ms 4600 KB Output is correct
51 Correct 26 ms 7896 KB Output is correct
52 Correct 24 ms 8124 KB Output is correct