Pagini recente » Cod sursa (job #3347826) | Cod sursa (job #2785356) | Cod sursa (job #279797) | Cod sursa (job #3324537) | Cod sursa (job #3343306)
#include <fstream>
#include <vector>
#include <algorithm>
#include <stack>
using namespace std;
ifstream cin("biconex.in");
ofstream cout("biconex.out");
int n,m;
int idx[100005],low[100005],T[100005],cnt;
vector<int> G[100005],c;
vector<vector<int>> cbc;
stack<pair<int,int>> stk;
void ExtractCbc(int x,int y)
{
c.clear();
while(!stk.empty())
{
auto [a,b]=stk.top();
stk.pop();
c.emplace_back(a);
c.emplace_back(b);
if(x==a && y==b)
break;
}
cbc.emplace_back(c);
}
void Tarjan(int x)
{
low[x]=idx[x]=++cnt;
for(auto y:G[x])
{
if(y==T[x])
continue;
if(!idx[y])
{
T[y]=x;
stk.emplace(x,y);
Tarjan(y);
low[x]=min(low[x],low[y]);
if(low[y]>=idx[x])
ExtractCbc(x,y);
}
else
low[x]=min(low[x],idx[y]);
}
}
int main()
{
cin>>n>>m;
for(int i=1;i<=m;i++)
{
int x,y;
cin>>x>>y;
G[x].emplace_back(y);
G[y].emplace_back(x);
}
for(int i=1;i<=n;i++)
if(!idx[i])
Tarjan(i);
cout<<cbc.size()<<"\n";
for(auto &c:cbc)
{
sort(c.begin(),c.end());
c.erase(unique(c.begin(),c.end()),c.end());
for(auto x:c)
cout<<x<<" ";
cout<<"\n";
}
return 0;
}