Pagini recente » Cod sursa (job #1223399) | Cod sursa (job #1614128) | Cod sursa (job #1123035) | Cod sursa (job #1585459) | Cod sursa (job #2580863)
#include <fstream>
#include <vector>
#include <cstring>
#include <stack>
#include <iostream>
using namespace std;
ifstream fin("biconex.in");
ofstream fout("biconex.out");
int n, m, nr;
int art[100005];
vector<int> pctArt;
int nivel[100005], low[100005];
vector<int> g[100005];
bool v[100005];
stack<pair<int, int> > st;
vector<vector<int> > bi;
void citire() {
fin >> n >> m;
while(m--) {
int x, y;
fin >> x >> y;
g[x].push_back(y);
g[y].push_back(x);
}
}
void dfs(int x, int t) {
v[x] = 1;
int nrcopii = 0;
nivel[x] = nivel[t]+1;
low[x] = nivel[x];
for(auto next: g[x]) {
if(!v[next]) {
nrcopii++;
st.push({x, next});
dfs(next, x);
if(low[next] >= nivel[x]) {
art[x] = true;
pair<int, int> curr;
vector<int> vec;
do {
curr = st.top();
vec.push_back(curr.first);
vec.push_back(curr.second);
st.pop();
} while(curr.first != x || curr.second != next);
bi.push_back(vec);
}
low[x] = min(low[x], low[next]);
} else if(next != t)
low[x] = min(low[x], nivel[next]);
}
}
void solve() {
for(int i = 1; i <= n; i++)
if(!v[i])
dfs(i, 0);
fout << bi.size() << '\n';
for(auto a: bi) {
for(auto x: a)
fout << x << ' ';
fout << '\n';
}
}
int main() {
citire();
solve();
}