Pagini recente » Cod sursa (job #2405978) | Cod sursa (job #882601) | Cod sursa (job #1518156) | Cod sursa (job #869862) | Cod sursa (job #3259772)
#include <fstream>
#include <vector>
#include <stack>
using namespace std;
ifstream cin ("biconex.in");
ofstream cout ("biconex.out");
const int N = 1e5;
int low[N + 1], discover[N + 1];
vector <int> g[N + 1], rez[N + 1];
stack <int> s;
stack <pair <int, int> > s_m;
int n, m, x, y, t, nr_comp;
void dfs (int node, int parent)
{
low[node] = discover[node] = ++t;
s.push (node);
for (auto it : g[node])
{
if (!discover[it])
{
s_m.push({node, it}); /// muchiile bagate
dfs (it, node);
low[node] = min (low[node], low[it]);///timpul minim de a ajung la el e de a ajunge la fii sai
if (low[it] > discover[node]);///(node, it) - bridge
if (low[it] >= discover[node])///node - punct de articulatie
{
rez[++nr_comp].push_back(node);
while (!s.empty() && s.top() != it)
rez[nr_comp].push_back(s.top()), s.pop();
if (!s.empty())
rez[nr_comp].push_back(s.top()), s.pop();
}
}
else
{
if (it != parent)///stramos(daca e muchie back)
s_m.push({node, it}), low[node] = min (low[node], discover[it]);
}
}
}
int main()
{
cin >> n >> m;
for (int i = 1; i <= m; ++i)
{
cin >> x >> y;
g[x].push_back(y);
g[y].push_back(x);
}
dfs (1, 0);
for (int i = 1; i <= nr_comp; ++i, cout << '\n')
for (auto it : rez[i])
cout << it << ' ';
return 0;
}