Pagini recente » Cod sursa (job #2619032) | Cod sursa (job #715545) | Cod sursa (job #855665) | Cod sursa (job #3174948) | Cod sursa (job #2476015)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("biconex.in");
ofstream fout("biconex.out");
const int NMAX=1e5+4;
int n,m,cnt,id;
int dfn[NMAX],low[NMAX];
stack <int> stk;
vector <int> g[NMAX];
vector <int> cb[NMAX];
void dfs(int node, int father){
stk.push(node);
low[node] = dfn[node] = ++id;
for(auto it:g[node]){
if(dfn[it] && it!=father)
low[node]=min(low[node], low[it]);
else if (!dfn[it]){
dfs(it,node);
low[node]=min(low[node], low[it]);
if(low[it] >= dfn[node]){
while(!stk.empty() && dfn[stk.top()] >= dfn[it]){
cb[cnt].push_back(stk.top());
stk.pop();
}
cb[cnt++].push_back(node);
}
}
}
}
int main(){
int x,y;
fin>>n>>m;
for(int i=0;i<m;++i){
fin>>x>>y;
g[x].push_back(y);
g[y].push_back(x);
}
dfs(1, 0);
fout<<cnt<<'\n';
for(int i=0;i<cnt;++i){
for(auto it:cb[i])
fout<<it<<' ';
fout<<'\n';
}
return 0;
}