Pagini recente » Cod sursa (job #1990212) | Cod sursa (job #1138933) | Cod sursa (job #2053554) | Cod sursa (job #1861752) | Cod sursa (job #1165472)
#include <fstream>
#include <vector>
#include <stack>
#include <algorithm>
using namespace std;
ifstream fin ("biconex.in");
ofstream fout ("biconex.out");
const int N = 1e5 + 5;
int n, m, niv[N], nr;
vector <int> g[N], comp[N];
vector <bool> viz(N, 0);
stack <pair <int, int> > stiva;
void dfs(int x, int father, int level) {
viz[x] = 1;
niv[x] = level;
for (vector <int> :: iterator it = g[x].begin(); it != g[x].end(); ++it) {
if (!viz[*it]) {
stiva.push (make_pair (x, *it));
dfs (*it, x, level + 1);
if (niv[*it] >= level) {
pair <int, int> extract;
do {
extract = stiva.top(); stiva.pop();
comp[nr].push_back (extract.first);
comp[nr].push_back (extract.second);
} while (extract.first != x || extract.second != *it);
nr++;
}
}
if (*it != father)
niv[x] = min(niv[x], niv[*it]);
}
}
int main() {
fin >> n >> m;
for (int x, y, i = 0 ; i< m; ++i) {
fin >> x >> y;
g[x].push_back (y);
g[y].push_back (x);
}
dfs (1, 0, 1);
fout << nr << "\n";
for (int i = 0; i < nr; ++i) {
sort (comp[i].begin(), comp[i].end());
for (vector <int> :: iterator it = comp[i].begin(); it != comp[i].end(); ++it)
fout << *it << " ";
fout << "\n";
}
}