dfs

#include<iostream>
#include<vector>
#include<string>
#include<map>
using namespace std;
#define MAX 1<<19
vector< vector<int> > v(MAX);
map<int, bool>visited;
int num = 0;//连通分量个数
//从k结点开始dfs
void dfs(int k) {
	for(int i=0;i<v[k].size();i++)
		if (!visited[v[k][i]]) {
			visited[v[k][i]] = true;
			dfs(v[k][i]);
		}
}
int main() {
	int a, b;
	string s = "start";
	while (getline(cin,s) ){
		if (s == "")break;
		int pos = s.find(" ", 0);
		a = stoi(s.substr(0, pos));
		b = stoi(s.substr(pos + 1, s.size() - pos - 1));
		//cout << "a=" << a << ", b=" << b << endl;
		v[a].push_back(b);
		v[b].push_back(a);
		visited[a] = false;
		visited[b] = false;
	}
	for (auto it = visited.begin(); it != visited.end();it++) {
		int id = it->first;
		if (!visited[id]) {
				
			//cout << "num=" << num << " ,id=" <<id<< endl;
			num++;
			visited[id] = true;
			dfs(id);
		}
	}
	cout << num << endl;

	return 0;
}