Pagini recente » Cod sursa (job #1452460) | Cod sursa (job #549364) | Cod sursa (job #525621) | Cod sursa (job #1309609) | Cod sursa (job #525134)
Cod sursa(job #525134)
#include<fstream>
#include<vector>
using namespace std;
ifstream in("dfs.in");
ofstream out("dfs.out");
const int N=100100;
vector<int>a[N];
int n,m;
bool viz[N];
#define pb push_back
void read()
{
int x,y;
in>>n>>m;
for(int i=1;i<=m;i++)
{
in>>x>>y;
a[x].pb(y);
a[y].pb(x);
}
}
void dfs(int x)
{
viz[x]=1;
for(int i=0;i<a[x].size();i++)
dfs(a[x][i]);
}
int main()
{
int count=0;
for(int i=1;i<=n;i++)
if(!viz[i])
{
count++;
dfs(i);
}
out<<count;
return 0;
}