Cod sursa(job #3300368)
| Utilizator | Data | 15 iunie 2025 09:02:47 | |
|---|---|---|---|
| Problema | Parcurgere DFS - componente conexe | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.66 kb |
#include <fstream>
#include <vector>
using namespace std;
ifstream fin("dfs.in");
ofstream fout("dfs.out");
const int nmax=100005;
bool viz[nmax];
vector<int> l[n];
void bfs(int nod);
{
viz[nod]=1;
for(int j : l[nod])
{
if(!viz[j])
bfs(j);
}
}
int main()
{
int n,m,x,nod;
fin>>n>>m>>x;
while(m--)
{
fin>>x>>y;
l[x].push_back(nod);
l[nod].push_back(x);
}
int nrcomp=0;
for(int i=1;i<=n;i++)
{ if(viz[i]==false)
{ nrcomp++;
dfs(i);
}
}
fout<<nrcomp;
return 0;
}
