Pagini recente » Monitorul de evaluare | Cod sursa (job #895793) | Cod sursa (job #1902457) | Cod sursa (job #2990005) | Cod sursa (job #2215471)
#include <fstream>
#include <vector>
#define nmax 100005
using namespace std;
ifstream f("biconex.in");
ofstream g("biconex.out");
int n, m, i, j, x, y, niv[nmax], lmax[nmax],stk[nmax], vf, comp;
bool seen[nmax];
vector<int>v[nmax], sol[nmax];
void get_component( int x, int k)
{
sol[comp].push_back(k);
while ( stk[vf] != x && vf > 0)
{
sol[comp].push_back( stk[vf] );
vf--;
}
if ( vf > 0)
{
sol[comp].push_back(x);
vf--;
}
}
void dfs( int x, int k)
{
int l = v[x].size(), y, i;
lmax[x] = niv[x] = niv[k]+1;
seen [x] = 1;
for ( i = 0; i < l; i++)
{
y = v[x][i];
if (y == k)
continue;
if ( seen [y] == 1)
{
lmax[x] = min(lmax[x], niv[y]);
continue;
}
stk[++vf] = y;
dfs( y , x );
lmax[x] = min(lmax[x], lmax[y]);
if (niv[x] <= lmax[y])
{
comp++;
get_component(y, x);
}
}
}
int main() {
f >> n >> m;
for (i = 1; i <= m; i++)
{
f >> x >> y;
v[x].push_back(y);
v[y].push_back(x);
}
for ( i = 1; i <= n; i++)
if (seen [i] == 0)
dfs(i,0);
g << comp << "\n";
for ( i = 1; i <= comp; i++)
{
for ( j = 0; j < sol[i].size(); j++)
g << sol[i][j] << ' ';
g << '\n';
}
return 0;
}