Pagini recente » Cod sursa (job #2089695) | Cod sursa (job #2181961) | Cod sursa (job #1208011) | Cod sursa (job #2652121) | Cod sursa (job #2404918)
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("biconex.in");
ofstream fout ("biconex.out");
const int nMax = 100010;
int n, m, h, a;
int low[nMax], height[nMax], st[nMax];
vector <int> v[nMax], ans[nMax];
void dfs(int nod)
{
st[++h] = nod;
for(auto it : v[nod])
{
if(!height[it])
{
int x = h;
height[it] = low[it] = height[nod] + 1;
dfs(it);
low[nod] = min(low[nod], low[it]);
if(low[it] >= height[nod])
{
ans[++a].push_back(nod);
while(h > x)
ans[a].push_back(st[h--]);
}
}
low[nod] = min(low[nod], height[it]);
}
}
int main()
{
fin >> n >> m;
for(int i=1, x, y; i<=m; i++)
{
fin >> x >> y;
v[x].push_back(y);
v[y].push_back(x);
}
low[1] = height[1] = 1;
dfs(1);
fout << a << '\n';
for(int i=1; i<=a; i++)
{
for(auto it : ans[i])
fout << it << " ";
fout << '\n';
}
}