Pagini recente » Cod sursa (job #1834062) | Cod sursa (job #968179) | Cod sursa (job #378266) | Cod sursa (job #2871042) | Cod sursa (job #1863796)
#include <bits/stdc++.h>
#define NMAX 100005
using namespace std;
ifstream fin("biconex.in");
ofstream fout("biconex.out");
int low[NMAX],level[NMAX];
stack < pair < int ,int > > S;
vector < int > G[NMAX];
vector < map < int, short> > V;
void Addcomponent(int x,int y){
map < int, short > aux;
int a,b;
do{
a = (S.top()).first;
b = (S.top()).second;
S.pop();
aux[a]++;
aux[b]++;
}while(x != a || y != b);
V.push_back(aux);
}
void DFS(int nod,int lvl){
low[nod] = level[nod] = lvl;
for(auto const &i : G[nod]){
if(low[i] == 0){
S.push({nod,i});
DFS(i,lvl + 1);
low[nod] = min(low[nod],low[i]);
if(low[i] >= level[nod])
Addcomponent(nod,i);
} else {
low[nod] = min(low[nod],level[i]);
}
}
}
int main()
{
ios :: sync_with_stdio(false);
fin.tie(NULL);
int n,m,x,y;
fin >> n >> m;
for(int i = 1; i <= m; i++){
fin >> x >> y;
G[x].push_back(y);
G[y].push_back(x);
}
DFS(1,1);
fout << V.size() << "\n";
for(auto const &i : V){
for(auto const &j : i)
fout << j.first << " ";
fout << "\n";
}
return 0;
}