Pagini recente » Cod sursa (job #3293353) | Monitorul de evaluare | Cod sursa (job #3293003) | Cod sursa (job #3293863) | Cod sursa (job #3292684)
#include <iostream>
#include <fstream>
#include <vector>
#define nl '\n'
using namespace std;
const int NMAX = 100001;
int N, M,
Niv[NMAX], Nma[NMAX],
S[NMAX], vf, nrCB;
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 DFS(int x, int tata)
{
S[++vf] = x;
viz[x] = 1;
Niv[x] = Niv[tata]+1;
Nma[x] = Niv[x];
for (const int &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);
fout << nrCB << nl;
for (int i = 1; i <= nrCB; i++)
{
for (const int &x : CB[i])
fout << x << ' ';
fout << nl;
}
return 0;
}