Pagini recente » Cod sursa (job #1302329) | Cod sursa (job #2834431) | Borderou de evaluare (job #3199123) | Cod sursa (job #2631201) | Cod sursa (job #3226529)
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <bitset>
#include <stack>
#include <set>
using namespace std;
ifstream fin("biconex.in");
ofstream fout("biconex.out");
vector <int> L[100005];
vector <set<int> > comp;
int low[100005], tin[100005], n, m;
stack <pair<int, int> > st;
bitset <100005> v;
void Component(int x, int y)
{
int tx, ty;
set <int> b;
do
{
tx = st.top().first;
ty = st.top().second;
st.pop();
b.insert(tx);
b.insert(ty);
} while (tx != x && ty != y);
comp.push_back(b);
}
void DFS(int k, int ant)
{
v[k] = 1;
tin[k] = low[k] = 1 + tin[ant];
for (int i : L[k])
{
if (i == ant) continue;
if (v[i] == 1)
low[k] = min(low[k], tin[i]);
else
{
st.push({ k, i });
DFS(i, k);
low[k] = min(low[k], low[i]);
if (tin[k] <= low[i])
Component(k, i);
}
}
}
int main()
{
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);
}
for (i = 1; i <= n; i++)
if (!v[i])
DFS(i, i);
fout << comp.size() << "\n";
for (i = 0; i < comp.size(); i++)
{
for (int j : comp[i])
fout << j << " ";
fout << '\n';
}
return 0;
}