Pagini recente » Cod sursa (job #1179279) | Cod sursa (job #2932088) | Cod sursa (job #3041968) | Cod sursa (job #3147665) | Cod sursa (job #2671032)
#include <bits/stdc++.h>
using namespace std;
ifstream f("biconex.in");
ofstream g("biconex.out");
int n,m,a[10005],b[10005],nr;
bool marker[10005];
stack <pair<int,int> > st;
vector <int> v[10005],sol[10005];
void dfs(int x,int nod)
{
marker[x]=true;
a[x]=b[x];
for(auto it : v[x])
{
if(!marker[it])
{
b[it]=1+b[x];
st.push({x,it});
dfs(it,x);
a[x]=min(a[x],a[it]);
if(a[it]>=b[x])
{
++nr;
while(!st.empty() && st.top().first!=x)
{
sol[nr].push_back(st.top().second);
st.pop();
}
sol[nr].push_back(st.top().second);
sol[nr].push_back(x);
st.pop();
}
}
else if(it!=nod)
{
a[x]=min(a[x],b[it]);
}
}
}
int main()
{
f>>n>>m;
for(int i=1;i<=m;i++)
{
int x,y;
f>>x>>y;
v[x].push_back(y);
v[y].push_back(x);
}
for(int i=1;i<=n;i++)
{
if(!marker[i])
{
dfs(i,0);
}
}
g<<nr<<'\n';
for(int i=1;i<=nr;i++)
{
sort(sol[i].begin(),sol[i].end());
for(auto it : sol[i])
{
g<<it<<" ";
}
g<<'\n';
}
return 0;
}