Pagini recente » Cod sursa (job #480195) | Cod sursa (job #1614855) | Cod sursa (job #3171661) | Cod sursa (job #2375634) | Cod sursa (job #2375734)
#include<bits/stdc++.h>
using namespace std;
ifstream f("biconex.in");
ofstream g("biconex.out");
int n,m,i,k,x,y,j,v1[100001],v2[100001],st[100001],nr;
vector <int>G[100001],rez[100001];
void dfs(int nod)
{
st[++k]=nod;
for(int i=0;i<G[nod].size();i++)
{
if(v1[G[nod][i]]==0)
{
int k2=k;
v1[G[nod][i]]=v1[nod]+1;
v2[G[nod][i]]=v1[nod]+1;
dfs(G[nod][i]);
v2[nod]=min(v2[nod],v2[G[nod][i]]);
if(v2[G[nod][i]]>=v1[nod])
{
nr++;
while(k>k2)
{
rez[nr].push_back(st[k]);
k--;
}
rez[nr].push_back(nod);
}
}
else
v2[nod]=min(v2[nod],v1[G[nod][i]]);
}
}
int main()
{
f>>n>>m;
for(i=1;i<=m;i++)
{
f>>x>>y;
G[x].push_back(y);
G[y].push_back(x);
}
v1[1]=1;
v2[1]=1;
dfs(1);
g<<nr<<'\n';
for(i=1;i<=nr;i++)
{
for(j=rez[i].size()-1;j>=0;j--)
g<<rez[i][j]<<" ";
g<<'\n';
}
return 0;
}