Pagini recente » Cod sursa (job #1468208) | Cod sursa (job #753980) | Cod sursa (job #59015) | Cod sursa (job #2946259) | Cod sursa (job #3042059)
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, m, timer, id[N], low[N];
vector <int> g[N];
stack <int> st;
vector <vector <int>> bcc;
void dfs(int u, int p = 0) {
id[u] = low[u] = id[p] + 1;
st.push(u);
for(int v : g[u]) {
if(id[v]) low[u] = min(low[u], id[v]);
else {
dfs(v, u);
low[u] = min(low[u], low[v]);
if(low[v] >= id[u]) {
bcc.push_back({u, v});
while(st.top() != v) {
bcc.back().push_back(st.top());
st.pop();
}
st.pop();
}
}
}
}
int main()
{
#ifndef HOME
ifstream cin("biconex.in");
ofstream cout("biconex.out");
#endif
ios_base :: sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> n >> m;
for(int i = 1, u, v; i <= m; i++) {
cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
}
for(int i = 1; i <= n; i++) if(!id[i])
dfs(i);
cout << bcc.size() << "\n";
for(auto& c : bcc) {
for(int x : c)
cout << x << " ";
cout << "\n";
}
return 0;
}