Pagini recente » Cod sursa (job #1592091) | Cod sursa (job #1442568) | Diferente pentru implica-te/arhiva-educationala intre reviziile 189 si 190 | Cod sursa (job #3209058) | Cod sursa (job #3289825)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("biconex.in");
ofstream fout("biconex.out");
vector <int> L[100005], art;
vector <set<int> > comp;
int depth[100005], low[100005], n, m, t;
bitset <100005> v;
stack <pair<int, int> > st;
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;
depth[k] = low[k] = 1 + depth[ant];
for (int i : L[k])
{
if (i == ant) continue;
if (v[i] == 1)
low[k] = min(low[k], depth[i]);
else
{
st.push({k, i});
DFS(i, k);
low[k] = min(low[k], low[i]);
if (depth[k] <= low[i])
{
art.push_back(k);
Component(k, i);
}
}
}
}
int main()
{
int i, j;
fin >> n >> m;
while (m--)
{
fin >> i >> j;
L[i].push_back(j);
L[j].push_back(i);
}
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;
}