#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int INF = 2e9;
int n , m;
vector<int> edge[N];
int low[N] , tin[N];
bool visited[N];
int timer = 0;
void dfs(int u , int p)
{
tin[u] = ++timer;
low[u] = INF;
visited[u] = true;
for (int i = 0 ; i < edge[u].size() ; ++i)
{
int v = edge[u][i];
bool bridge = true;
if (p == v) continue;
if (i + 1 < edge[u].size() && edge[u][i + 1] == v) bridge = false;
if (i - 1 >= 0 && edge[u][i - 1] == v) bridge = false;
if (visited[v])
{
low[u] = min(low[u] , tin[v]);
}
else
{
dfs(v , u);
if (low[v] > tin[u] && bridge)
{
cout << u << " " << v << "\n";
}
low[u] = min(low[u] , low[v]);
}
}
}
int parent[2*N] , level[2*N];
int find_set(int u)
{
if (u == parent[u]) return u;
return parent[u] = find_set(parent[u]);
}
bool same_set(int u , int v)
{
return find_set(u) == find_set(v);
}
int union_set(int u , int v)
{
int set1 = find_set(u);
int set2 = find_set(v);
if (level[set1] < level[set2]) swap(set1 , set2);
parent[set2] = set1;
if (level[set1] == level[set2]) ++level[set1];
}
int main()
{
// freopen(".inp","r",stdin);
// freopen(".out","w",stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for (int i = 1 ; i <= 2*n ; ++i) parent[i] = i;
while(m--)
{
int u , v;
cin >> u >> v;
if (!same_set(u , v))
{
union_set(u , v);
edge[u].push_back(v);
edge[v].push_back(u);
}
else if (!same_set(u + n , v + n))
{
union_set(u + n , v + n);
edge[u].push_back(v);
edge[v].push_back(u);
}
}
for (int i = 1 ; i <= n ; ++i) sort(edge[i].begin() , edge[i].end());
// for (int i = 1 ; i <= n ; ++i) tin[i] = low[i] = -1 , visited[i] = false;
for (int i = 1 ; i <= n ; ++i)
{
if (!visited[i])
{
dfs(i , -1);
}
}
// cout << "\n";
// for (int i = 1 ; i <= n ; ++i) cout << low[i] << " " << tin[i] << "\n";
}
Compilation message
pipes.cpp: In function 'void dfs(int, int)':
pipes.cpp:20:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
20 | for (int i = 0 ; i < edge[u].size() ; ++i)
| ~~^~~~~~~~~~~~~~~~
pipes.cpp:26:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
26 | if (i + 1 < edge[u].size() && edge[u][i + 1] == v) bridge = false;
| ~~~~~~^~~~~~~~~~~~~~~~
pipes.cpp: In function 'int union_set(int, int)':
pipes.cpp:66:1: warning: no return statement in function returning non-void [-Wreturn-type]
66 | }
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
5 ms |
5228 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
6 ms |
5356 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
5 ms |
5376 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
6 ms |
5496 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
6 ms |
5612 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
6 ms |
6380 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
7 ms |
6508 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
7 ms |
7020 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
7 ms |
7040 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
8 ms |
6764 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |