Pagini recente » Cod sursa (job #120674) | Cod sursa (job #2258037) | Cod sursa (job #2478630) | Cod sursa (job #2149910) | Cod sursa (job #1642772)
#include <fstream>
#include <vector>
#include <stack>
#include <algorithm>
#define INF 0x3f3f3f3f
using namespace std;
ifstream is("biconex.in");
ofstream os("biconex.out");
using VI = vector<int>;
using VVI = vector<VI>;
int n, m, cnt;
VI c, nv, nm, t;
VVI g, ctc;
stack<pair<int, int>> s;
void Read();
void Write();
void Solve(int nod);
int main()
{
Read();
nv = nm = t = VI(n + 1);
Solve(1);
Write();
is.close();
os.close();
return 0;
}
void Solve(int nod)
{
nv[nod] = nm[nod] = ++cnt;
for ( const auto &nodv : g[nod] )
{
if ( t[nod] == nodv )
continue;
if ( !nv[nodv] )
{
s.push(make_pair(nod, nodv));
t[nodv] = nod;
Solve(nodv);
nm[nod] = min(nm[nod], nm[nodv]);
if ( nm[nodv] >= nv[nod] )
{
c.clear();
int n1, n2;
do {
c.push_back(n1 = s.top().first);
c.push_back(n2 = s.top().second);
s.pop();
}
while ( n1 != nod && n2 != nodv );
sort(c.begin(), c.end());
c.erase(unique(c.begin(), c.end()), c.end());
ctc.push_back(c);
}
}
else
nm[nod] = min(nm[nod], nv[nodv]);
}
}
void Read()
{
is >> n >> m;
g = VVI(n + 1);
int x, y;
while ( m-- )
{
is >> x >> y;
g[x].push_back(y);
g[y].push_back(x);
}
}
void Write()
{
os << ctc.size() << "\n";
for ( const auto &i : ctc )
{
for ( const auto &j : i )
os << j << " ";
os << "\n";
}
}