Pagini recente » Cod sursa (job #2134854) | Cod sursa (job #1660325) | Cod sursa (job #1485479) | Cod sursa (job #1261587) | Cod sursa (job #2723444)
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("biconex.in");
ofstream fout ("biconex.out");
void usain_bolt()
{
ios::sync_with_stdio(false);
fin.tie(0);
}
const int N = 1e5 + 5;
vector < int > a[N], add;
vector < vector < int > > sol;
stack < pair < int, int > > st;
int disc[N], low[N], temp;
void found(int x, int y)
{
vector < int > add;
int topf = st.top().first, tops = st.top().second;
do {
topf = st.top().first, tops = st.top().second;
add.push_back(topf);
add.push_back(tops);
st.pop();
}
while(topf != x && tops != y);
sol.push_back(add);
}
void dfs(int k)
{
disc[k] = low[k] = ++temp;
for(auto v : a[k]) {
if(disc[v] == 0) {
st.push({k, v});
dfs(v);
low[k] = min(low[k], low[v]);
if(low[v] >= disc[k]) {
found(k, v);
}
}
else {
low[k] = min(low[k], disc[v]);
}
}
}
int main()
{
usain_bolt();
int n, m;
fin >> n >> m;
for(int i = 1; i <= m; ++i) {
int x, y;
fin >> x >> y;
a[x].push_back(y);
a[y].push_back(x);
}
for(int i = 1; i <= n; ++i) {
if(disc[i] == false) {
dfs(i);
}
}
fout << (int) sol.size() << "\n";
for(auto v : sol) {
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
for(auto w : v) {
fout << w << " ";
}
fout << "\n";
}
return 0;
}