# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
546473 |
2022-04-07T16:09:06 Z |
rainboy |
Pipes (CEOI15_pipes) |
C |
|
448 ms |
13340 KB |
#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 time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
852 KB |
Output is correct |
2 |
Correct |
2 ms |
724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
39 ms |
976 KB |
Output is correct |
2 |
Correct |
32 ms |
844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
51 ms |
1736 KB |
Output is correct |
2 |
Correct |
69 ms |
1336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
112 ms |
3556 KB |
Output is correct |
2 |
Correct |
90 ms |
3484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
132 ms |
9412 KB |
Output is correct |
2 |
Correct |
121 ms |
6092 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
204 ms |
10992 KB |
Output is correct |
2 |
Correct |
197 ms |
8204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
272 ms |
13340 KB |
Output is correct |
2 |
Correct |
282 ms |
8736 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
324 ms |
13304 KB |
Output is correct |
2 |
Correct |
331 ms |
8764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
448 ms |
12556 KB |
Output is correct |
2 |
Correct |
374 ms |
10376 KB |
Output is correct |