# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
545888 |
2022-04-05T15:54:21 Z |
rainboy |
Pipes (CEOI15_pipes) |
C |
|
1384 ms |
65536 KB |
#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
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 time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
980 KB |
Output is correct |
2 |
Correct |
3 ms |
724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
139 ms |
6264 KB |
Output is correct |
2 |
Correct |
121 ms |
5888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
217 ms |
11160 KB |
Output is correct |
2 |
Correct |
250 ms |
12452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
362 ms |
19512 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
452 ms |
30108 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
689 ms |
43900 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
883 ms |
57036 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1162 ms |
65536 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1384 ms |
65536 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |