제출 #546473

#제출 시각아이디문제언어결과실행 시간메모리
546473rainboyPipes (CEOI15_pipes)C11
100 / 100
448 ms13340 KiB
#include <ctype.h> #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 read() { char c; int a; while (!isdigit(c = getchar())) ; a = 0; for ( ; isdigit(c); c = getchar()) a = a * 10 + c - '0'; return a; } int main() { static int ds1[N], ds2[N]; int n, m, m_, h, i, j; n = read(), m = read(); memset(ds1, -1, n * sizeof *ds1); memset(ds2, -1, n * sizeof *ds2); m_ = 0; while (m--) { i = read() - 1, j = read() - 1; 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; }
#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...