Pagini recente » Cod sursa (job #1029333) | Cod sursa (job #1233101) | Cod sursa (job #2142268) | Cod sursa (job #2227062) | Cod sursa (job #3218972)
#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,-1),low(NMAX,-1);
bitset<NMAX> art;
int nr_comp_biconex, timp, nrfii,start;
stack <pii> St;
set<int> Comp[NMAX];
void afisare_comp_biconex(int x, int y){
nr_comp_biconex++;
pii p;
do{
p = St.top();St.pop();
Comp[nr_comp_biconex].insert(p.first);
Comp[nr_comp_biconex].insert(p.second);
}while(p.first!=x || p.second!=y);
}
void dfs(int x, int p = -1){
d[x] = low[x] = ++timp;
for(int y : G[x]){
if(y!= p && d[x] > d[y]) St.push({x,y});
if(d[y]==-1){
if(x == start) nrfii++;
dfs(y,x);
low[x] = min(low[x],low[y]);
if(low[y]>=d[x]){
if(x != start) art[x] = true;
afisare_comp_biconex(x,y);
}
}else if(y != p) low[x] = min( low[x],d[y]);
}
}
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);
}
St.push({1,-1});
start=1;
dfs(1);
cout<<nr_comp_biconex<<'\n';
for(int i=1;i<=nr_comp_biconex;i++){
for(auto j : Comp[i]) cout<<j<<' ';
cout<<'\n';
}
return 0;
}