Pagini recente » Cod sursa (job #2881641) | Cod sursa (job #1506539) | Cod sursa (job #1964967) | Cod sursa (job #2670083) | Cod sursa (job #2261744)
#include <bits/stdc++.h>
#define Nmax 100001
using namespace std;
ifstream f("biconex.in");
ofstream g("biconex.out");
list <int> G[Nmax];
int dfn[Nmax];
int low[Nmax];
vector < vector <int> > comp_bic;
stack < pair <int,int> > st;
vector <int> v;
int n,m,N,xx,yy;
void DFS(int x, int root)
{
low[x]=dfn[x]=++N;
for(const auto &it:G[x])
if(it!=root)
{
if(dfn[it]==-1)
{
st.push({x,it});
DFS(it,x);
low[x]=min(low[x],low[it]);
if(low[it]>=dfn[x])
{
do
{
xx=st.top().first;
yy=st.top().second;
v.push_back(xx);
v.push_back(yy);
st.pop();
}while(xx!=x and yy!=it);
sort(v.begin(),v.end());
v.erase(unique(v.begin(),v.end()),v.end());
comp_bic.push_back(v);
v.clear();
}
}
else
low[x]=min(low[x],dfn[it]);
}
}
int main()
{
int i,j;
f>>n>>m;
while(m--)
{
f>>i>>j;
G[i].push_back(j);
G[j].push_back(i);
}
fill(dfn+1,dfn+n+1,-1);
fill(low+1,low+n+1,-1);
DFS(1,-1);
g<<comp_bic.size()<<'\n';
for(const auto it:comp_bic)
{
for(const auto i:it) g<<i<<' ';
g<<'\n';
}
return 0;
}