Pagini recente » Cod sursa (job #1771592) | Cod sursa (job #255545) | Cod sursa (job #691045) | Cod sursa (job #48396) | Cod sursa (job #3246358)
#include <fstream>
#include <vector>
#include <bitset>
using namespace std;
ifstream fin ("ctc.in");
ofstream fout ("ctc.out");
bitset <100001> viz;
vector <int> s,v[1000001];
vector <vector <int>> sol;
int n,m,i,j,x,y,k,nr,niv[1000001],stiva[1000001],low[1000001];
void dfs (int nod,int t,int nivel)
{
viz[nod]=1;
niv[nod]=low[nod]=nivel;
stiva[++k]=nod;
for (int i=0; i<v[nod].size (); i++)
{
int vecin=v[nod][i];
if (viz[vecin])
low[nod]=min (low[nod],low[vecin]);
else
{
dfs (vecin,nod,nivel+1);
low[nod]=min (low[nod],low[vecin]);
if (niv[nod]<low[vecin])
{
s.clear ();
do
{
nr=stiva[k];
s.push_back (nr);
k--;
}
while (nr!=vecin);
sol.push_back (s);
}
}
}
if (nod==1)
{
s.clear ();
while (k>0)
s.push_back (stiva[k--]);
sol.push_back (s);
}
}
int main()
{
fin>>n>>m;
for (i=1; i<=m; i++)
{
fin>>x>>y;
v[x].push_back (y);
}
dfs (1,0,1);
fout<<sol.size ()<<"\n";
for (i=0; i<sol.size (); i++)
{
for (j=0; j<sol[i].size (); j++)
fout<<sol[i][j]<<" ";
fout<<"\n";
}
return 0;
}