Pagini recente » Cod sursa (job #1374492) | Cod sursa (job #2175713) | Cod sursa (job #2539613) | Cod sursa (job #919582) | Cod sursa (job #2811681)
#include <fstream>
#include <vector>
#include <stack>
using namespace std;
const int N = 1e5 + 1;
int n, m, t[N], t_min[N], timp, n_cbc;
vector <int> a[N];
vector <int> cbc[N];
stack <int> stiva;
void adauga_cbc(int x, int y)
{
n_cbc++;
while (stiva.top() != y)
{
cbc[n_cbc].push_back(stiva.top());
stiva.pop();
}
cbc[n_cbc].push_back(y);
cbc[n_cbc].push_back(x);
stiva.pop();
}
void dfs(int x, int tata)
{
t_min[x] = t[x] = ++timp;
stiva.push(x);
for (auto y: a[x])
{
if (t[y] == 0)
{
dfs(y, x);
t_min[x] = min(t_min[x], t_min[y]);
if (t_min[y] >= t[x])
{
//p_art.push_back(x);///x este punct de articulatie
adauga_cbc(x, y);
}
}
else if (y != tata)
{
t_min[x] = min(t_min[x], t[y]);
}
}
}
int main()
{
ifstream in("biconex.in");
ofstream out("biconex.out");
in >> n >> m;
for (int i = 0; i < m; i++)
{
int x, y;
in >> x >> y;
a[x].push_back(y);
a[y].push_back(x);
}
in.close();
for (int i = 1; i <= n; i++)
{
if (t[i] == 0)
{
dfs(i, 0);
}
}
out << n_cbc << "\n";
for (int i = 1; i <= n_cbc; i++)
{
for (auto x: cbc[i])
{
out << x << " ";
}
out << "\n";
}
out.close();
return 0;
}