Pagini recente » Cod sursa (job #80235) | Cod sursa (job #1934646) | Cod sursa (job #2678088) | Cod sursa (job #1198747) | Cod sursa (job #1522642)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream fin("biconex.in");
ofstream fout("biconex.out");
#define MAX 100010
typedef vector <int> :: iterator iter;
vector <int> G[MAX], comp;
vector <vector <int> > ans;
int viz[MAX], ad[MAX], de[MAX], dr;
pair<int, int> st[MAX];
void df(int nod, int dad)
{
viz[nod] = 1;
ad[nod] = ad[dad] + 1;
de[nod] = ad[nod];
for(iter it = G[nod].begin() ; it != G[nod].end() ; it++)
{
if(*it == dad)
continue;
if(!viz[*it])
{
st[++dr] = make_pair(nod, *it);
df(*it, nod);
de[nod] = min(de[nod], de[*it]);
if(de[*it] >= ad[nod])
{
comp.clear();
while(st[dr].first != nod || st[dr].second != *it)
comp.push_back(st[dr--].second);
comp.push_back(*it);
comp.push_back(nod);
dr--;
ans.push_back(comp);
}
}
else
de[nod] = min(de[nod], ad[*it]);
}
}
int main()
{
int n, m, x, y, i;
fin >> n >> m;
while(m--)
{
fin >> x >> y;
G[x].push_back(y);
G[y].push_back(x);
}
for(i = 1 ; i <= n ; i++)
if(!viz[i])
df(i, 0);
fout << ans.size() << "\n";
for(vector <vector <int> > :: iterator it = ans.begin() ; it != ans.end() ; it++)
{
for(iter it1 = it->begin() ; it1 != it->end() ; it1++)
fout << *it1 << " ";
fout << "\n";
}
}