Pagini recente » Cod sursa (job #2495626) | Cod sursa (job #391104) | Cod sursa (job #2483513) | Cod sursa (job #2714219) | Cod sursa (job #2801006)
#include <bits/stdc++.h>
using namespace std;
ifstream f("biconex.in");
ofstream g("biconex.out");
const int NMAX=100001;
vector<int>G[NMAX],CB[NMAX];
int N,M,
nrCB,
Niv[NMAX],Nma[NMAX],
S[NMAX],vf;
bool viz[NMAX];
void citire()
{
int x,y;
cin>>N>>M;
for(int i=1;i<=M;i++){
cin>>x>>y;
G[x].push_back(y);
G[y].push_back(x);
}
}
void DFS(int x,int tata)
{
S[++vf]=x;
viz[x]=1;
Niv[x]=Niv[tata]+1;
Nma[x]=Niv[x];
for(auto &y : G[x])
{
if(y==tata) continue;
if(viz[y])
Nma[x]=min(Nma[x],Niv[y]);
else
{
DFS(y,x);
Nma[x]=min(Nma[x],Nma[y]);
//
if(Niv[x]<=Nma[y])
{
++nrCB;
while(S[vf]!=y)
CB[nrCB].push_back(S[vf--]);
CB[nrCB].push_back(y);
--vf;
CB[nrCB].push_back(x);
}
}
}
}
int main()
{
citire();
DFS(1,0);
cout<<nrCB<<'\n';
for(int i=1;i<=nrCB;i++)
{
for(auto &x : CB[i])
cout<<x<<' ';
cout<<'\n';
}
return 0;
}