Pagini recente » Cod sursa (job #1832443) | Cod sursa (job #1220072) | Cod sursa (job #267536) | Cod sursa (job #880818) | Cod sursa (job #2594484)
#include <bits/stdc++.h>
using namespace std;
const int len = 100005;
int m, n, x, y, cnt, aux, depth[len], low[len];
vector<bool> seen(len, false);
vector<int> g[len], sol[len];
stack<int> s;
void dfs(int node, int parent = 0) {
low[node] = depth[node] = depth[parent] + 1;
seen[node] = true;
s.push(node);
for (int& next : g[node])
if (next != parent) {
if (seen[next])
low[node] = min(low[node], depth[next]);
else {
dfs(next, node);
low[node] = min(low[node], low[next]);
if (low[next] >= depth[node]) {
do {
aux = s.top();
sol[cnt].push_back(aux);
s.pop();
} while (aux != next);
sol[cnt++].push_back(node);
}
}
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
freopen("biconex.in", "r", stdin);
freopen("biconex.out", "w", stdout);
cin >> n >> m;
while (m--) {
cin >> x >> y;
g[x].push_back(y);
g[y].push_back(x);
}
for (int i = 0; i < n; i++)
if (!seen[i])
dfs(i);
cout << cnt << "\n";
for (int i = 0; i < cnt; i++) {
for (int& it : sol[i])
cout << it << " ";
cout << "\n";
}
}