Cod sursa(job #2601537)
| Utilizator | Data | 14 aprilie 2020 17:12:32 | |
|---|---|---|---|
| Problema | Parcurgere DFS - componente conexe | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.46 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("dfs.in");
ofstream fout("dfs.out");
int nod,muchii,a[10005][10005],nr,v[10005];
void dfs( int x)
{ nr++;
v[x]=1;
for(int i=1;i<=nod;i++)
if(v[i]==0&&a[x][i]==1)
dfs(i);
}
int main()
{ int x,y;
fin>>nod>>muchii;
for( int i=1;i<=muchii;i++)
{
fin>>x>>y;
a[x][y]=1;
a[y][x]=1;
}
dfs(1);
fout<<nr;
}
