Pagini recente » Cod sursa (job #2341087) | Borderou de evaluare (job #1392912) | Cod sursa (job #802165) | Cod sursa (job #63243) | Cod sursa (job #2814758)
#include <fstream>
#include <vector>
#include <stack>
using namespace std;
ifstream in("biconex.in");
ofstream out("biconex.out");
const int N = 1e5+2;
int n, m, t[N], t_min[N], timp, cntcbc;
vector <int> a[N], cbc[N];
stack<int> stiva;
void adauga_cbc(int x, int y)
{
cntcbc++;
while(stiva.top()!=y)
{
cbc[cntcbc].push_back(stiva.top());
stiva.pop();
}
cbc[cntcbc].push_back(x);
cbc[cntcbc].push_back(y);
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()
{
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<<cntcbc<<'\n';
for(int i=1; i<=cntcbc; i++)
{
for (auto x: cbc[i])
{
out << x << " ";
}
out<<'\n';
}
return 0;
}