#include using namespace std; using ll = long long; class DisjointSets { public: DisjointSets(const int v) { m_parent.resize(v); m_rank.resize(v); m_size.resize(v); for (int i = 0; i < v; i++) { m_parent[i] = i; m_rank[i] = 0; m_size[i] = 1; } } bool same(const int a, const int b) { return find(a) == find(b); } int find(const int a) { if (m_parent[a] == a) { return a; } else { return m_parent[a] = find(m_parent[a]); } } void unite(const int a_, const int b_) { const int a = find(a_); const int b = find(b_); if (a == b) { return; } if (m_rank[a] > m_rank[b]) { m_parent[b] = a; m_size[a] += m_size[b]; } else { m_parent[a] = b; m_size[b] += m_size[a]; } if (m_rank[a] == m_rank[b]) { m_rank[b]++; } } int getSize(const int a) { return m_size[m_parent[a]]; } private: vector m_parent; vector m_rank; vector m_size; }; int main() { cin.tie(0); ios::sync_with_stdio(false); int N, M; cin >> N >> M; DisjointSets uf(N); for (int i = 0; i < M; i++) { int a, b, c; cin >> a >> b >> c; a--, b--; uf.unite(a, b); } vector num(N, 0); for (int i = 0; i < N; i++) { num[uf.find(i)] = 1; } const int cnt = accumulate(num.begin(), num.end(), 0); cout << cnt << endl; return 0; }