Mai intai trebuie sa te autentifici.
Cod sursa(job #2350257)
| Utilizator | Data | 21 februarie 2019 10:34:43 | |
|---|---|---|---|
| Problema | Parcurgere DFS - componente conexe | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.68 kb |
#include <fstream>
#include <vector>
#define MAX 100100
using namespace std;
ifstream fin("dfs.in");
ofstream fout("dfs.out");
void citire();
void DFS(int x);
vector <int> G[MAX];
bool uz[MAX];
int n, m, c;
int main()
{int i;
citire();
for(i=1;i<=n;i++)
if(!uz[i])
{
c++;
DFS(i);
}
fout << c;
}
void citire()
{int i, x, y;
fin >> n >> m;
for(i=0;i<m;i++)
{
fin >> x >> y;
G[x].push_back(y);
G[y].push_back(x);
}
}
void DFS(int x)
{int i;
//fout << x << ' ';
uz[x] = 1;
for(i=0;i<G[x].size();i++)
if(!uz[G[x][i]]) DFS(G[x][i]);
}
