Pagini recente » Cod sursa (job #59460) | Cod sursa (job #753029) | Cod sursa (job #2106242) | Cod sursa (job #513569) | Cod sursa (job #2984441)
#include <fstream>
#include <vector>
using namespace std;
ifstream fin("biconex.in");
ofstream fout("biconex.out");
int const N = 2e5 + 3;
int n , m , a , b , c , k , B;
int idx[N] , low[N] , st[N];
vector<int> v[N] , bcx[N];
void baga_biconexa(int x , int y){
++B;
while(k > 0 && st[k] != y){
bcx[B].push_back(st[k--]);
}
bcx[B].push_back(st[k--]);
bcx[B].push_back(x);
}
void dfs(int x){
idx[x] = low[x] = ++c;
st[++k] = x;
for(int y : v[x]){
if(!idx[y]){
dfs(y);
low[x] = min(low[x] , low[y]);
if(low[y] >= idx[x]){
baga_biconexa(x , y);
}
}else{
low[x] = min(low[x] , idx[y]);
}
}
}
int main(){
fin >> n >> m;
for(int i = 1 ; i <= m ; ++ i){
fin >> a >> b;
v[a].push_back(b);
v[b].push_back(a);
}
for(int i = 1 ; i <= n ; ++ i){
if(!idx[i])
dfs(i);
}
fout << B << '\n';
for(int i = 1 ; i <= B ; ++ i){
for(int y : bcx[i])
fout << y << ' ';
fout << '\n';
}
return 0;
}