Pagini recente » Cod sursa (job #1519732) | Cod sursa (job #326768) | Cod sursa (job #1650245) | Cod sursa (job #1990647) | Cod sursa (job #1466049)
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#define Nmax 100002
using namespace std;
int n, m, i, j, d[Nmax], v[Nmax], used[Nmax], c, nexti, nre;
vector < int > V[Nmax], C[Nmax];
bool viz[Nmax];
struct edge
{
int x;
int y;
} scc[Nmax];
void read()
{
int x, y;
freopen("biconex.in", "r", stdin);
freopen("biconex.out", "w", stdout);
scanf("%d %d", &n, &m);
for (i = 1; i <= m; ++ i)
{
scanf("%d %d", &x, &y);
V[x].push_back(y);
V[y].push_back(x);
}
}
void bcc(int x, int y)
{
edge e;
do
{
e = scc[nre--];
if (used[e.x] != c)
{
C[c].push_back(e.x);
used[e.x] = c;
}
if (used[e.y] != c)
{
C[c].push_back(e.y);
used[e.y] = c;
}
if (e.x == x && e.y == y)
break;
} while (nre > 0);
++ c;
}
void dfs(int x)
{
int i, l = V[x].size(), nrs = 0;
viz[x] = 1;
d[x] = v[x] = ++ nexti;
for (i = 0; i < l; ++ i)
if (!viz[V[x][i]])
{
scc[++ nre].x = x;
scc[nre].y = V[x][i];
++ nrs;
dfs(V[x][i]);
d[x] = min(d[x], d[V[x][i]]);
if (d[V[x][i]] >= v[x])
bcc(x, V[x][i]);
}
else d[x] = min(d[x], v[V[x][i]]);
}
void solve()
{
for (i = 1; i <= n; ++ i)
used[i] = -1;
for (i = 1; i <= n; ++ i)
if (!viz[i])
{
viz[i] = 1;
nre = 0;
dfs(i);
}
}
void write()
{
int l;
printf("%d\n", c);
for (i = 0; i < c; ++ i)
{
l = C[i].size();
for (j = 0; j < l; ++ j)
printf("%d ", C[i][j]);
printf("\n");
}
}
int main()
{
read();
solve();
write();
return 0;
}