Pagini recente » Cod sursa (job #2684496) | Cod sursa (job #2802001) | Cod sursa (job #1996240) | Cod sursa (job #2437168) | Cod sursa (job #365972)
Cod sursa(job #365972)
#include<fstream>
#define Nmax 100001
using namespace std;
ifstream fin("biconex.in");
ofstream fout("biconex.out");
int n;
int dfn[Nmax],low[Nmax];
int numar_componente,nr_ordine;
struct nod
{int info;
nod *urm;
};
nod *l[Nmax];
void citire()
{int i,x,y,m;
fin>>n>>m;
for(i=1;i<=m;i++)
{fin>>x>>y;
nod *c;
c=new nod;
c->info=y;
c->urm=l[x];
l[x]=c;
c=new nod;
c->info=x;
c->urm=l[y];
l[y]=c;
}
}
int minim(int x,int y)
{if(x>y) return y;
return x;
}
void biconex(int u,int tatal)
{int x;
nod *c;
nr_ordine++;
dfn[u]=low[u]=nr_ordine;
for(c=l[u];c!=NULL;c=c->urm)
{x=c->info;
if(dfn[x]==0)
{biconex(x,u);
low[u]=minim(low[u],low[x]);
if(low[x]>=dfn[u])
numar_componente++;
}
else
if(x!=tatal)
low[u]=min(low[u],dfn[x]);
}
}
int main()
{citire();
biconex(3,-1);
fout<<numar_componente;
fin.close();
fout.close();
return 0;
}