Pagini recente » Cod sursa (job #3332696) | Cod sursa (job #1683940) | Cod sursa (job #2582126) | Cod sursa (job #2560660) | Cod sursa (job #3322675)
#include <fstream>
#include <vector>
#include <set>
using namespace std;
const int NMAX = 1e5 + 1;
struct muchie
{
int x, y;
muchie(int xx = 0, int yy = 0)
{
x = xx, y = yy;
}
};
int N, M, nrCB,
Niv[NMAX], Nma[NMAX],
S[NMAX], vf;
vector<int> G[NMAX], CB[NMAX];
bool viz[NMAX];
ifstream fin("biconex.in");
ofstream fout("biconex.out");
void citire()
{
int x, y;
fin >> N >> M;
for(int i = 1; i <= M; ++i)
{
fin >> x >> y;
G[x].push_back(y);
G[y].push_back(x);
}
}
void DFScb(int x, int tata)
{
S[++vf] = x;
viz[x] = 1;
Niv[x] = Niv[tata] + 1;
Nma[x] = Niv[x];
for(const auto &y : G[x])
{
if(y == tata) continue;
if(viz[y])
Nma[x] = min(Nma[x], Niv[y]);
else
{
DFScb(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();
DFScb(1, 0);
fout << nrCB << '\n';
for(int i = 1; i <= nrCB; ++i)
{
for(const auto &x : CB[i]) fout << x << ' ';
fout << '\n';
}
return 0;
}