Pagini recente » Cod sursa (job #848577) | Cod sursa (job #3150277) | Cod sursa (job #585067) | Cod sursa (job #737068) | Cod sursa (job #1571839)
#include <fstream>
#include <vector>
#include <algorithm>
#include <stack>
#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;
VI nv, nm, t, c;
VVI g, answ;
stack<pair<int, int>> s;
void Read();
void CB(int nod, int niv);
void Write();
void Make(int x, int y);
int main()
{
Read();
nv = nm = t = VI(n + 1);
for ( int i = 1; i <= n; ++i )
if ( !nv[i] )
{
CB(i, 1);
t[i] = i;
}
Write();
is.close();
os.close();
return 0;
}
void CB(int nod, int niv)
{
nv[nod] = nm[nod] = niv;
for ( const auto &nodv : g[nod] )
{
if ( t[nod] == nodv )
continue;
if ( !nv[nodv] )
{
t[nodv] = nod;
s.push(make_pair(nod, nodv));
CB(nodv, niv + 1);
if ( nm[nodv] > nm[nod] )
Make(nod, nodv);
}
else
nm[nod] = min(nm[nod], nv[nodv]);
}
}
void Make(int x, int y)
{
c.clear();
while ( true )
{
c.push_back(s.top().first);
c.push_back(s.top().second);
if ( x == s.top().first && y == s.top().second )
break;
s.pop();
}
s.pop();
sort(c.begin(), c.end());
c.erase(unique(c.begin(), c.end()), c.end());
answ.push_back(c);
}
void Write()
{
os << answ.size() << "\n";
for ( const auto i : answ )
{
for ( const auto j : i )
os << j << " ";
os << "\n";
}
}
void Read()
{
is >> n >> m;
g = VVI(n + 1);
int x, y;
for ( int i = 1; i <= n; ++i )
{
is >> x >> y;
g[x].push_back(y);
g[y].push_back(x);
}
}