Pagini recente » Cod sursa (job #247352) | Cod sursa (job #1940359) | Cod sursa (job #2838319) | Cod sursa (job #118502) | Cod sursa (job #2866800)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("biconex.in");
ofstream fout("biconex.out");
struct muchie
{
int nod1, nod2;
};
int n, m;
vector<int> L[100003];
stack<muchie> st;
int lowest[100003], nivel[100003];
bitset<100003> viz;
vector<int> sol[100003];
int nrcb;
void Citire()
{
int i, x, y;
fin >> n >> m;
for (i = 1; i <= m; i++)
{
fin >> x >> y;
L[x].push_back(y);
L[y].push_back(x);
}
}
void DFS(int nod, int tata)
{
lowest[nod] = nivel[nod] = 1 + nivel[tata];
viz[nod] = 1;
for (int f : L[nod])
{
if (viz[f])
{
lowest[nod] = min(lowest[nod], nivel[f]);
continue;
}
st.push({ nod, f });
DFS(f, nod);
lowest[nod] = min(lowest[nod], lowest[f]);
if (nivel[nod] == lowest[f])
{
nrcb++;
while (st.top().nod1 != nod || st.top().nod2 != f)
{
sol[nrcb].push_back(st.top().nod2);
st.pop();
}
sol[nrcb].push_back(st.top().nod2);
sol[nrcb].push_back(st.top().nod1);
st.pop();
}
}
}
void Afisare()
{
int i;
fout << nrcb << "\n";
for (i = 1; i <= nrcb; i++)
{
for (int elem : sol[i])
fout << elem << " ";
fout << "\n";
}
fout.close();
}
int main()
{
Citire();
DFS(1, 0);
Afisare();
}