#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0)
#define mp make_pair
#define xx first
#define yy second
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(x) x.begin(),x.end()
#define ff(i,a,b) for (int i = a; i < b; i++)
#define fff(i,a,b) for (int i = a; i <= b; i++)
#define bff(i,a,b) for (int i = b-1; i >= a; i--)
#define bfff(i,a,b) for (int i = b; i >= a; i--)
using namespace std;
long double typedef ld;
unsigned int typedef ui;
long long int typedef li;
pair<int,int> typedef pii;
pair<li,li> typedef pli;
pair<ld,ld> typedef pld;
vector<vector<int>> typedef graph;
unsigned long long int typedef ull;
//const int mod = 998244353;
const int mod = 1000000007;
//Note to self: Check for overflow
int up[2][100005];
int Up(bool c, int x)
{
if (up[c][x]<0) return x;
return up[c][x]=Up(c,up[c][x]);
}
bool dsu(bool c, int a, int b)
{
a=Up(c,a),b=Up(c,b);
if (a==b) return false;
if (up[c][a]<up[c][b]) swap(a,b);
up[c][b]+=up[c][a],up[c][a]=b;
return true;
}
int par[100010];
int idx[100010];
int lowl[100010];
int nt;
vector<int> edge[100010];
void dfs(int x){
idx[x] = lowl[x] = ++nt;
bool cl = false;
for(int y:edge[x]){
if(par[x] == y && !cl){
cl=true; continue;
}
if(!idx[y]){
par[y]=x;
dfs(y);
lowl[x] = min(lowl[x], lowl[y]);
} else lowl[x] = min(lowl[x], idx[y]);
}
if(par[x] && idx[x]==lowl[x]) cout<<x<<" "<<par[x]<<"\n";
}
int main()
{
FAST;
int n,m; cin>>n>>m;
ff(c,0,2) fff(i,1,n) up[c][i]=-1;
while (m--)
{
int u,v; cin>>u>>v;
if (dsu(0,u,v) || dsu(1,u,v)) edge[u].pb(v),edge[v].pb(u);
}
fff(i,1,n) if (up[0][i]<0) dfs(i);
}
//Note to self: Check for overflow
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
3260 KB |
Output is correct |
2 |
Correct |
5 ms |
3028 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
88 ms |
8476 KB |
Output is correct |
2 |
Correct |
95 ms |
8204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
159 ms |
13232 KB |
Output is correct |
2 |
Correct |
186 ms |
14640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
283 ms |
21488 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
353 ms |
30904 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
572 ms |
44492 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
734 ms |
57408 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
902 ms |
65536 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1062 ms |
65536 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |