Pagini recente » Cod sursa (job #2523124) | Cod sursa (job #1927858) | Cod sursa (job #2827483) | Cod sursa (job #3240112) | Cod sursa (job #3218990)
#include <bits/stdc++.h>
#define pii pair<int,int>
#define eb emplace_back
//#define ll long long
#define pll pair<ll,ll>
using namespace std;
int n,m;
const int NMAX = 1e5+1;
vector<int> G[NMAX], d(NMAX),low(NMAX), Comp[NMAX], St;
int nr, timp;
void dfs(int x, int p = -1){
d[x] = low[x] = ++timp;
St.push_back(x);
for(int y : G[x]){
if(y == p) continue;
if(d[y]){
low[x] = min(low[x],d[y]);
}else{
dfs(y,x);
low[x] = min(low[x],low[y]);
if(low[y]>=d[x]){
nr++;
while(!St.empty() && St.back()!=y){
Comp[nr].push_back(St.back());St.pop_back();
}
Comp[nr].push_back(St.back());
Comp[nr].push_back(x);
St.pop_back();
}
}
}
}
int main() {
ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
freopen("biconex.in","r",stdin);
freopen("biconex.out","w",stdout);
cin>>n>>m;
for(int i=1;i<=m;i++){
int x,y;
cin>>x>>y;
G[x].eb(y);G[y].eb(x);
}
dfs(1);
cout<<nr<<'\n';
for(int i=1;i<=nr;i++){
sort(Comp[i].begin(),Comp[i].end());
for(int j : Comp[i]) cout<<j<<' ';
cout<<'\n';
}
return 0;
}