Pagini recente » Cod sursa (job #2327605) | Cod sursa (job #691622) | Cod sursa (job #638322) | Cod sursa (job #2335241) | Cod sursa (job #2744477)
#include <fstream>
#include <vector>
using namespace std;
ifstream f("biconex.in");
ofstream g("biconex.out");
const int NMAX = 100001;
int N, M,
nrCB,
Niv[NMAX], Nma[NMAX],
S[NMAX], vf;
bool viz[NMAX];
vector<int> G[NMAX];
vector<int>CB[NMAX];
void citire()
{
f >> N >> M;
for(int i = 1; i <= M; ++i)
{
int x, y;
f >> 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(auto &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);
g << nrCB << '\n';
for(int i = 1; i <= nrCB; ++i)
{
for(auto &x : CB[i])
g << x << ' ';
g << '\n';
}
return 0;
}