Pagini recente » Cod sursa (job #1451297) | Cod sursa (job #491042) | Cod sursa (job #1991582) | Cod sursa (job #573794) | Cod sursa (job #2462025)
#include <bits/stdc++.h>
#define Nmax 100005
using namespace std;
ifstream fin ("biconex.in");
ofstream fout ("biconex.out");
struct muchie
{
int a, b;
};
stack <muchie> s;
vector <int> v[Nmax];
vector < vector <int> > c;
int l[Nmax], niv[Nmax], t[Nmax], i, j, n, m, nr, x, y;
void dfs(int x, int tata)
{
int i;
l[x]=niv[x];
for(i=0; i<v[x].size(); i++)
{
if(niv[x]>niv[v[x][i]]&&v[x][i]!=tata)
s.push({x, v[x][i]});
if(niv[v[x][i]]==0)
{
niv[v[x][i]]=niv[x]+1;
dfs(v[x][i], x);
if(l[x]>l[v[x][i]])
l[x]=l[v[x][i]];
if(l[v[x][i]]>=niv[x])
{
nr++;
vector <int> aux;
muchie u;
while(1)
{
u=s.top();
s.pop();
aux.push_back(u.a);
aux.push_back(u.b);
if((u.a==x&&u.b==v[x][i])||(u.a==v[x][i]&&u.b==x))
break;
}
c.push_back(aux);
}
}
else if(v[x][i]!=tata&&niv[v[x][i]]<l[x])
l[x]=niv[v[x][i]];
}
}
int main()
{
fin >> n >> m;
for(i=1; i<=m; i++)
{
fin >> x >> y;
v[x].push_back(y);
v[y].push_back(x);
}
niv[1]=1;
dfs(1, 0);
fout << nr << '\n';
for(i=0;i<nr;i++)
{
sort(c[i].begin(), c[i].end());
c[i].erase(unique(c[i].begin(), c[i].end()), c[i].end());
for(j=0;j<c[i].size();j++)
fout << c[i][j] << ' ';
fout << '\n';
}
return 0;
}