Pagini recente » Cod sursa (job #2738207) | Cod sursa (job #2237791) | Cod sursa (job #2286157) | Cod sursa (job #2296339) | Cod sursa (job #1923067)
#include <fstream>
#include <vector>
#include <stack>
#include <algorithm>
using namespace std;
ifstream fin("biconex.in");
ofstream fout("biconex.out");
int n, m;
int nrc, root, nr;
vector<vector<int>> G, CC;
vector<int> t, niv, L, C;
vector<bool> s, p;
stack<pair<int, int>> S;
void Read();
void DFS(int x, int nv);
void Write();
int main() {
Read();
root = 1;
DFS(root, 1);
Write();
fin.close();
fout.close();
return 0;
}
void DFS(int x, int nv) {
if (nv == 2) nr++;
s[x] = true;
L[x] = niv[x] = nv;
for (const auto & y : G[x]) {
if (y == t[x]) continue;
if (!s[y]) {
t[y] = x;
S.push({x, y});
DFS(y, nv + 1);
L[x] = min(L[x], L[y]);
if (niv[x] <= L[y]) {
nrc++;
C.clear();
int x1, x2;
while (true) {
x1 = S.top().first;
x2 = S.top().second;
S.pop();
C.push_back(x1);
C.push_back(x2);
if (x1 == x && x2 == y) break;
}
CC.push_back(C);
}
}
else
L[x] = min(L[x], niv[y]);
}
}
void Write() {
fout << nrc << '\n';
for (auto & c : CC) {
sort(c.begin(), c.end());
c.erase(unique(c.begin(), c.end()), c.end());
for (const auto & x : c)
fout << x << ' ';
fout << '\n';
}
}
void Read() {
fin >> n >> m;
G = vector<vector<int>>(n + 1);
L = niv = t = vector<int>(n + 1);
s = p = vector<bool>(n + 1);
int x, y;
for (int i = 1; i <= m; i++) {
fin >> x >> y;
G[x].push_back(y);
G[y].push_back(x);
}
}