Pagini recente » Cod sursa (job #1980288) | Cod sursa (job #2925863) | Cod sursa (job #2429248) | Cod sursa (job #429484) | Cod sursa (job #925355)
Cod sursa(job #925355)
#include<fstream>
#include<iostream>
using namespace std;
struct nod
{int nd;
nod *next;};
nod *L[20];
int viz[100],n,vf,S[100],m;
void df()
{ nod *c;
int nr;
if(vf)
{ c=L[S[vf]];
// cout<<S[vf]<<" ";
vf--;
while(c)
{ nr=c->nd;
if(viz[nr]==0)
{vf++;
S[vf]=nr;
viz[nr]=1;}
c=c->next;
}
df();
}
}
int main()
{ifstream f("df.in");
int i,j,nr=0;
nod *p,*q;
f>>n>>m;
while(f>>i>>j)
{p=new nod;
p->nd=j;
p->next=L[i];
L[i]=p;
q=new nod;
q->nd=i;
q->next=L[j];
L[j]=q;
}
f.close();
for(int k=1;k<=n;k++)
if(viz[k]==0)
{ viz[k]=1;
vf=1;
S[vf]=k;
df();
nr++;}
cout<<"nr de componente conexe "<<nr;
return 0;
}