Pagini recente » Cod sursa (job #1644977) | Cod sursa (job #1630673) | Cod sursa (job #134536) | Cod sursa (job #2038732) | Cod sursa (job #365963)
Cod sursa(job #365963)
#include<fstream>
#define Nmax 5001
using namespace std;
ifstream fin("biconex.in");
ofstream fout("biconex.out");
int n,a[Nmax][Nmax];
int dfn[Nmax],low[Nmax];
int numar_componente,nr_ordine;
void citire()
{int i,x,y,m;
fin>>n>>m;
for(i=1;i<=m;i++)
{fin>>x>>y;
a[x][0]++;
a[x][a[x][0]]=y;
a[y][0]++;
a[y][a[y][0]]=x;
}
}
int minim(int x,int y)
{if(x>y) return y;
return x;
}
void biconex(int u,int tatal)
{int x,i;
nr_ordine++;
dfn[u]=low[u]=nr_ordine;
for(i=1;i<=a[u][0];i++)
{x=a[u][i];
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]=dfn[x];
}
}
int main()
{citire();
biconex(3,-1);
fout<<numar_componente;
fin.close();
fout.close();
return 0;
}