Submission #545888

#TimeUsernameProblemLanguageResultExecution timeMemory
545888rainboyPipes (CEOI15_pipes)C11
40 / 100
1384 ms65536 KiB
#include <stdio.h> #include <stdlib.h> #include <string.h> #define N 100000 #define M ((N - 1) * 2) int min(int a, int b) { return a < b ? a : b; } int ii[M], jj[M]; char bridge[M]; int *eh[N], eo[N]; void append(int i, int h) { eh[i][eo[i]++] = h; } int find(int *ds, int i) { return ds[i] < 0 ? i : (ds[i] = find(ds, ds[i])); } int join(int *ds, int i, int j) { i = find(ds, i), j = find(ds, j); if (i == j) return 0; if (ds[i] > ds[j]) ds[i] = j; else { if (ds[i] == ds[j]) ds[i]--; ds[j] = i; } return 1; } int ta[N], tb[N]; void dfs(int f, int i) { static int time; int o; ta[i] = tb[i] = ++time; for (o = eo[i]; o--; ) { int h = eh[i][o], j = i ^ ii[h] ^ jj[h]; if (h != f) { if (!ta[j]) { dfs(h, j); tb[i] = min(tb[i], tb[j]); if (tb[j] == ta[j]) bridge[h] = 1; } else tb[i] = min(tb[i], ta[j]); } } } int main() { static int ds1[N], ds2[N]; int n, m, m_, h, i, j; scanf("%d%d", &n, &m); memset(ds1, -1, n * sizeof *ds1); memset(ds2, -1, n * sizeof *ds2); m_ = 0; while (m--) { scanf("%d%d", &i, &j), i--, j--; if (join(ds1, i, j) || join(ds2, i, j)) { ii[m_] = i, jj[m_] = j, m_++; eo[i]++, eo[j]++; } } m = m_; for (i = 0; i < n; i++) eh[i] = (int *) malloc(eo[i] * sizeof *eh[i]), eo[i] = 0; for (h = 0; h < m; h++) append(ii[h], h), append(jj[h], h); for (i = 0; i < n; i++) if (!ta[i]) dfs(-1, i); for (h = 0; h < m; h++) if (bridge[h]) printf("%d %d\n", ii[h] + 1, jj[h] + 1); return 0; }

Compilation message (stderr)

pipes.c: In function 'main':
pipes.c:61:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |  scanf("%d%d", &n, &m);
      |  ^~~~~~~~~~~~~~~~~~~~~
pipes.c:66:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   66 |   scanf("%d%d", &i, &j), i--, j--;
      |   ^~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...