Cod sursa(job #1165440)

Utilizator UVS_Elfus_Deneo_KiraUVS-Elfus-Dutzul-Kira UVS_Elfus_Deneo_Kira Data 2 aprilie 2014 18:10:44
Problema Componente biconexe Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.67 kb
#include<fstream>
#include<cstdio>
#include<set>
#include<stack>
#include<vector>
#include<algorithm>
#define FOR(a,b,c) for(int a=b;a<=c;++a)
#include<cstring>
#include<bitset>
#include<cmath>
#include<iomanip>
#include<queue>
#define f cin
#define g cout
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ll long long
#define bit 20
#define inf (1<<30)
#define base 256
#define ba 255
#define N 100100
#define inu "biconex.in"
#define outu "biconex.out"
using namespace std;
ifstream f(inu);
ofstream g(outu);
//int dx[]={0,0,0,1,-1};
//int dy[]={0,1,-1,0,0};
vector<int> C[N],v[N];
stack<pair<int,int> > st;
int niv[N],low[N],n,m,cbc,x,y;
void dfs(int x,int dad,int lvl)
{
    niv[x]=low[x]=lvl;
    for(int i=0;i<v[x].size();++i)
    if(v[x][i]!=dad)
    {
        if(!niv[v[x][i]])
        {
            st.push(mp(x,v[x][i]));
            dfs(v[x][i],x,lvl+1);
            if(low[v[x][i]]>=niv[x])
            {
                ++cbc;
                int y=v[x][i];
                int a=0,b=0;
                do
                {
                    a=st.top().first;
                    b=st.top().second;
                    st.pop();
                    C[cbc].pb(b);
                }
                while(a!=x&&b!=y);
                C[cbc].pb(x);
            }
        }
        low[x]=min(low[x],low[v[x][i]]);
    }
}
int main ()
{
    f>>n>>m;
    FOR(i,1,m)
    {
        f>>x>>y;
        v[x].push_back(y);
		v[y].push_back(x);
    }
    dfs(1,-1,1);
    g<<cbc<<"\n";
    FOR(i,1,cbc)
    {
    FOR(j,0,C[i].size()-1)
    g<<C[i][j]<<" ";
    g<<"\n";
    }
    return 0;
}