Pagini recente » Cod sursa (job #1004004) | Cod sursa (job #2235292) | Cod sursa (job #2095773) | Statistici Serban Robert (Robert_Serban) | Cod sursa (job #1828321)
#include <bits/stdc++.h>
#define nmax 110
using namespace std;
ofstream g("date.out");
vector <int> v[nmax];
int n, m, nc, viz[nmax];
int dfs(int nod, int nc)
{
viz[nod] = nc;
for(int i = 0; i < v[nod].size(); i ++)
{
if(!viz[v[nod][i]])
dfs(v[nod][i], nc);
}
}
void citire()
{
ifstream f("date.in");
f>>n>>m;
for(int i = 1; i <= m; i++)
{
int x, y;
f>>x>>y;
v[x].push_back(y);
v[y].push_back(x);
}
f.close();
}
int main()
{
citire();
for(int i = 1; i <= n; i++ )
if(!viz[i])
{
nc++;
dfs(i, nc);
}
g<<nc;
return 0;
}