Submission #949047

#TimeUsernameProblemLanguageResultExecution timeMemory
949047rainboy작은 사이클들 (YDX13_smallcycles)C11
1 / 1
41 ms13904 KiB
#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)

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 timeMemoryGrader output
Fetching results...