Pagini recente » Cod sursa (job #2292033) | Cod sursa (job #2388780) | Cod sursa (job #1955416) | Cod sursa (job #1790270) | Cod sursa (job #2654683)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("biconex.in");
ofstream fout("biconex.out");
const int nmax = 100005;
int n, m, low[nmax], id[nmax], z, s;
pair <int, int> stiva[nmax * 2];
vector <int> G[nmax];
vector <vector <int> > ans;
void biconex(int a, int b){
for (int i = 1; i <= s; ++i){
cout << stiva[i].first << " " << stiva[i].second << "\n";
}
cout << "\n";
int x, y;
vector <int> aux;
while (stiva[s].first != a && stiva[s].second != b){
x = stiva[s].first;
y = stiva[s].second;
--s;
aux.push_back(y);
}
aux.push_back(stiva[s].second);
aux.push_back(stiva[s].first);
--s;
ans.push_back(aux);
}
void dfs(int nod){
id[nod] = low[nod] = ++z;
for (auto it : G[nod]){
if (id[it] == 0){
stiva[++s] = {nod, it};
dfs(it);
low[nod] = min(low[nod], low[it]);
if (low[it] >= id[nod]){
biconex(nod, it);
}
}
else{
low[nod] = min(low[nod], id[it]);
}
}
}
int main(){
fin >> n >> m;
for (int i = 1; i <= m; ++i){
int x, y;
fin >> x >> y;
G[x].push_back(y);
G[y].push_back(x);
}
dfs(1);
fout << ans.size() << "\n";
for (int i = 0; i < ans.size(); ++i){
for (int j = 0; j < ans[i].size(); ++j){
fout << ans[i][j] << " ";
}
fout << "\n";
}
fin.close();
fout.close();
return 0;
}