Pagini recente » Cod sursa (job #2207086) | Cod sursa (job #909282) | Cod sursa (job #779270) | Cod sursa (job #2893688) | Cod sursa (job #2118989)
#include <iostream>
#include <bits/stdc++.h>
#define INFILE "biconex.in"
#define OUTFILE "biconex.out"
#define RADACINA_FICTIVA -1
using namespace std;
typedef pair<int,int> edge;
ifstream in(INFILE);
ofstream out(OUTFILE);
int N,M;
vector<vector<int>> ComponenteBiconexe;
map<int,int> dnum;
map<int,int> low;
stack<edge> S;
void AddToCompBiconexe(int x,int y){
vector<int> v;
int tx,ty;
do{
tx=S.top().first;
ty=S.top().second;
v.push_back(tx),v.push_back(ty);
S.pop();
}while(tx!=x||ty!=y);
ComponenteBiconexe.push_back(v);
}
struct Graph{
int n;
vector<vector<int>> Adj;
void Init(int sz){
n=sz;
Adj.resize(n+1);
}
void Add(int x,int y){
Adj[x].push_back(y);
Adj[y].push_back(x);
}
}G;
void Read(){
in>>N>>M;
G.Init(N);
for(int i=1;i<=M;i++){
int x,y;
in>>x>>y;
// cout<<x<<" "<<y<<endl;
G.Add(x,y);
}
}
void DFS(int x,int tx,int number){
viz[x]=true;
dnum[x]=low[x]=number;
for(auto y:G.Adj[x]){
if(y==tx) continue;
if(dnum[y]==0){
S.push(make_pair(x,y));
DFS(y,x,number+1);
low[x]=min(low[x],low[y]);
if(low[y]>=dnum[x])
AddToCompBiconexe(x,y);
}
else{
low[x]=min(low[x],dnum[y]);
}
}
}
int main()
{
Read();
DFS(1,RADACINA_FICTIVA,1);
out<<ComponenteBiconexe.size()<<"\n";
for(auto c:ComponenteBiconexe){
sort(c.begin(),c.end());
c.erase(unique(c.begin(),c.end()),c.end());
for(auto e:c){
out<<e<<" ";
}
out<<"\n";
}
return 0;
}