Cod sursa(job #2032993)
Utilizator | Data | 5 octombrie 2017 22:45:31 | |
---|---|---|---|
Problema | Parcurgere DFS - componente conexe | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.42 kb |
#include <fstream>
#include <vector>
using namespace std;
ifstream f("a.in");
ofstream g("a.out");
vector <int> G[100001];
int i,j,m,n,viz[100001],nr,x,y;
int main()
{f>>n>>m;
for(i=1;i<=m;i++)
{
f>>x>>y;
G[x].push_back(y);
G[y].push_back(x);
}
for(i=1;i<=n;i++)
if(viz[i]==0){
nr++;
for(j=0;j<G[i].size();j++)
viz[G[i][j]]=1;
}
g<<nr;
return 0;
}