Pagini recente » Cod sursa (job #2769828) | Cod sursa (job #1176221) | Cod sursa (job #1740180) | Cod sursa (job #412058) | Cod sursa (job #2800076)
#include <fstream>
#include <vector>
#include <stack>
using namespace std;
ifstream in("biconex.in");
ofstream out("biconex.out");
int n,m,x,y,nr,niv[100010],nivmin[100010];
vector<vector<int>>a,r;
stack<int>s;
bool v[100010];
void arbore(int t,int n)
{
v[n]=true;
nivmin[n]=niv[n];
s.push(n);
for(auto x:a[n])
{
if(x==t)
continue;
if(v[x]==true)
{
nivmin[n]=min(nivmin[n],niv[x]);
continue;
}
niv[x]=niv[n]+1;
arbore(n,x);
nivmin[n]=min(nivmin[n],nivmin[x]);
if(nivmin[x]>=niv[n])
{
++nr;
while(!s.empty()&&s.top()!=x)
{
r[nr].push_back(s.top());
s.pop();
}
r[nr].push_back(s.top());
s.pop();
r[nr].push_back(n);
}
}
return;
}
int main()
{
in>>n>>m;
a.resize(n+5);
r.resize(n+5);
for(int i=1;i<=m;++i)
{
in>>x>>y;
a[x].push_back(y);
a[y].push_back(x);
}
arbore(0,1);
out<<nr<<'\n';
for(int i=1;i<=nr;++i)
{
for(auto x:r[i])
out<<x<<' ';
out<<'\n';
}
return 0;
}