Pagini recente » Cod sursa (job #357200) | Cod sursa (job #616973) | Cod sursa (job #686460) | Cod sursa (job #2256616) | Cod sursa (job #2853099)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("biconex.in");
ofstream fout("biconex.out");
const int MAXN = 1e5 + 5;
int timer, nrc;
int low[MAXN], lvl[MAXN];
bool viz[MAXN];
vector<int> G[MAXN], CC[MAXN], st;
void Componenta(int node, int last) {
nrc++;
while(st.back() != last)
CC[nrc].push_back(st.back()), st.pop_back();
CC[nrc].push_back(node);
}
void DFS(int node, int father = 0) {
viz[node] = 1;
lvl[node] = low[node] = ++timer;
st.push_back(node);
for(auto son : G[node])
if(viz[son] == 0) {
int last = st.back();
DFS(son, node);
low[node] = min(low[node], low[son]);
if(lvl[node] <= low[son])
Componenta(node, last);
}
else if(son != father)
low[node] = min(low[node], lvl[son]);
}
int main() {
int n, m;
fin >> n >> m;
while(m--) {
int x, y;
fin >> x >> y;
G[x].push_back(y);
G[y].push_back(x);
}
DFS(1);
fout << nrc << '\n';
for(int i = 1; i <= nrc; i++) {
for(auto node : CC[i])
fout << node << ' ';
fout << '\n';
}
return 0;
}