Cod sursa(job #2911596)
Utilizator | Data | 30 iunie 2022 17:21:26 | |
---|---|---|---|
Problema | Parcurgere DFS - componente conexe | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.4 kb |
#include<bits/stdc++.h>
using namespace std;
ifstream f("dfs.in");
ofstream g("dfs.out");
int n,i,x,y,c;
vector<int> v[100001];
bool z[100001];
void D(int x)
{
z[x]=1;
for(auto y:v[x])
if(!z[y])
D(y);
}
int main()
{
for(f>>n>>x;f>>x>>y;v[x].push_back(y),v[y].push_back(x));
for(i=1;i<=n;++i)
if(!z[i])
++c,D(i);
return g<<c,0;
}