#include<bits/stdc++.h>
using namespace std;
const int N = 100005, M = 140005;
int n, cnt, tk, H[N], Mn[N], stk[N], par[N];
int ts, head[N], nxt[M + M];
int m, from[M], to[M];
bitset < M > tree, bridge;
bitset < N > mark;
inline void Unlaze()
{
mark = 0; tree = 0;
memset(H, 0, sizeof(H));
for (int i = 1; i <= n; i++)
if (!mark[i])
{
tk = 1;
stk[tk] = i;
par[tk] = -1;
/* DFS */
int v, u;
while (tk)
{
v = stk[tk];
if (mark[v])
{
u = from[head[v] >> 1] ^ to[head[v] >> 1] ^ v;
Mn[v] = min(Mn[v], Mn[u]);
if (Mn[u] < H[u])
bridge[head[v] >> 1] = 0;
head[v] = nxt[head[v]];
}
if (!mark[v])
{
mark[v] = 1;
Mn[v] = H[v];
}
for (; head[v] != -1; head[v] = nxt[head[v]])
if ((head[v] >> 1) != par[tk])
{
u = from[head[v] >> 1] ^ to[head[v] >> 1] ^ v;
if (mark[u])
Mn[v] = min(Mn[v], H[u]), bridge[head[v] >> 1] = 0;
else
{
H[u] = H[v] + 1;
tree[head[v] >> 1] = 1;
++ tk;
stk[tk] = u;
par[tk] = head[v] >> 1;
break;
}
}
if (head[v] == -1)
tk --;
}
/* DFS */
}
cnt = 0;
for (int i = 0; i < (ts >> 1); i++)
if (tree[i])
{
bool _bool;
_bool = tree[i];
tree[i] = tree[cnt];
tree[cnt] = _bool;
_bool = bridge[i];
bridge[i] = bridge[cnt];
bridge[cnt] = _bool;
swap(from[i], from[cnt]);
/*from[i] ^= from[cnt];
from[cnt] ^= from[i];
from[i] ^= from[cnt];*/
swap(to[i], to[cnt]);
/*to[i] ^= to[cnt];
to[cnt] ^= to[i];
to[i] ^= to[cnt];*/
cnt ++;
}
ts = 0;
memset(nxt, -1, sizeof(nxt));
memset(head, -1, sizeof(head));
for (int i = 0; i < cnt; i++)
{
int v, u;
v = from[i]; u = to[i];
from[ts >> 1] = v; to[ts >> 1] = u;
nxt[ts] = head[v]; head[v] = ts;
nxt[ts|1] = head[u]; head[u] = ts|1;
ts += 2;
}
}
int main()
{
memset(nxt, -1, sizeof(nxt));
memset(head, -1, sizeof(head));
scanf("%d%d", &n, &m);
for (int i = 1; i <= m; i++)
{
int v, u;
scanf("%d%d", &v, &u);
bridge[ts >> 1] = 1;
from[ts >> 1] = v; to[ts >> 1] = u;
nxt[ts] = head[v]; head[v] = ts;
nxt[ts|1] = head[u]; head[u] = ts|1;
ts += 2;
if (ts >= M + M - 20)
Unlaze();
}
Unlaze();
for (int i = 0; i < (ts >> 1); i++)
if (bridge[i])
printf("%d %d\n", from[i], to[i]);
return 0;
}
Compilation message
pipes.cpp: In function 'int main()':
pipes.cpp:102:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &n, &m);
~~~~~^~~~~~~~~~~~~~~~
pipes.cpp:106:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &v, &u);
~~~~~^~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2176 KB |
Output is correct |
2 |
Correct |
3 ms |
2304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2304 KB |
Output is correct |
2 |
Correct |
6 ms |
2304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
151 ms |
3420 KB |
Output is correct |
2 |
Correct |
152 ms |
3404 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
272 ms |
3492 KB |
Output is correct |
2 |
Correct |
324 ms |
3320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
503 ms |
3580 KB |
Output is correct |
2 |
Correct |
377 ms |
3612 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
961 ms |
4000 KB |
Output is correct |
2 |
Correct |
683 ms |
3708 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1540 ms |
4092 KB |
Output is correct |
2 |
Correct |
1185 ms |
3940 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2745 ms |
4136 KB |
Output is correct |
2 |
Correct |
2289 ms |
3832 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3463 ms |
4140 KB |
Output is correct |
2 |
Correct |
3140 ms |
3952 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3547 ms |
4116 KB |
Output is correct |
2 |
Correct |
2785 ms |
4052 KB |
Output is correct |