Pagini recente » Cod sursa (job #157689) | Cod sursa (job #2794748) | Cod sursa (job #1050399) | Cod sursa (job #1182836) | Cod sursa (job #1676752)
#include <fstream>
#include <vector>
#include <algorithm>
#include <stack>
#define NMAX 100005
using namespace std;
ifstream f("biconex.in");
ofstream g("biconex.out");
int i, n, m, cnt = 0, low[NMAX], lvl[NMAX], x, y;
bool used[NMAX];
vector < int > v[NMAX], ans[NMAX];
stack < pair < int, int > > st;
void DFS(int node, int father)
{
used[node] = 1;
lvl[node] = lvl[father] + 1;
low[node] = lvl[node];
for (auto & it : v[node])
{
if (used[it])
low[node] = min(low[node], lvl[it]);
else
{
st.push({it, node});
DFS(it, node);
low[node] = min(low[node], low[it]);
if (low[it] >= lvl[node])
{
cnt ++;
while (st.top().first != it && st.top().second != node)
{
ans[cnt].push_back(st.top().first);
st.pop();
}
ans[cnt].push_back(node);
ans[cnt].push_back(it);
st.pop();
}
}
}
}
int main()
{
f >> n >> m;
for (i = 1; i <= m; ++ i)
{
f >> x >> y;
v[x].push_back(y);
v[y].push_back(x);
}
DFS(1, 0);
g << cnt << '\n';
for (i = 1; i <= cnt; ++ i)
{
for (auto & it : ans[i])
g << it << " " ;
g << '\n';
}
return 0;
}