Pagini recente » Cod sursa (job #2274918) | Cod sursa (job #1764993) | Cod sursa (job #2401699) | Cod sursa (job #1431247) | Cod sursa (job #2834715)
#include<bits/stdc++.h>
#define int long long
using namespace std;
ifstream fin ("biconex.in");
ofstream fout("biconex.out");
const int dim = 100002;
int niv[dim], low[dim], st[dim], vf, nrc;
vector <int> sol[dim], a[dim];
bool viz[dim];
void dfs (int x,int tata)
{
st[++vf] = x;
viz[x] = 1;
niv[x] = niv[tata] + 1;
low[x] = niv[x];
for (int y : a[x])
if (viz[y])
{
if (low[x] > niv[y])
low[x] = niv[y];
}
else
{
dfs (y, x);
if (low[x] > low[y])
low[x] = low[y];
if (niv[x] <= low[y])
{
++nrc;
while (st[vf] != y)
{
sol[nrc].push_back(st[vf]);
vf--;
}
--vf;
sol[nrc].push_back(y);
sol[nrc].push_back(x);
//st[++vf] = x;
}
}
}
int32_t main()
{
int n, m, x, y;
fin >> n >> m;
while (m--)
{
fin >> x >> y;
a[x].push_back(y);
a[y].push_back(x);
}
dfs (1, 0);
fout << nrc << '\n';
for (int i = 1; i <= nrc; i++)
{
for (int w : sol[i])
fout << w << ' ';
fout << '\n';
}
}