Pagini recente » Cod sursa (job #355612) | Cod sursa (job #142719) | Cod sursa (job #1510137) | Cod sursa (job #154324) | Cod sursa (job #278530)
Cod sursa(job #278530)
#include<stdio.h>
#define in "df.in"
#define out "df.out"
struct nod{
long nd;
nod *next;
}*l[100001],*p;
long n,m,x,y,i,s[100001],cont;
void df(int);
int main()
{
freopen(in,"r",stdin);
freopen(out,"w",stdout);
scanf("%ld%ld",&n,&m);
for(i=1;i<=m;i++)
{
scanf("%ld%ld",&x,&y);
p=new nod;
p->nd=y;
p->next=l[x];
l[x]=p;
p=new nod;
p->nd=x;
p->next=l[y];
l[y]=p;
}
for(i=1;i<=n;i++)
{
if(!s[i])
{
df(i);
cont++;
}
}
printf("%ld",cont);
return 0;
}
void df(int nodd)
{
s[nodd]=1;
nod *q;
q=l[nodd];
while(q)
{
if(!s[q->nd])
{
df(q->nd);
}
q=q->next;
}
}