#include #include #include #include #include #include #include #include #include #include #include #include #include #define repd(i,a,b) for (int i=(a);i<(b);i++) #define rep(i,n) repd(i,0,n) #define var auto #define mod 1000000007 #define inf 2147483647 #define nil -1 #define mp make_pair typedef long long ll; using namespace std; template inline void output(T a, int p) { if(p){ cout << fixed << setprecision(p) << a << "\n"; } else{ cout << a << "\n"; } } // end of template int main() { cin.tie(0); // source code int N, M; cin >> N >> M; vector> edge(N); set vis; rep(i, N){ vis.insert(i); } rep(i, M){ int a, b, c; cin >> a >> b >> c; a--, b--; edge[a].push_back(b); edge[b].push_back(a); } queue q; int ret = 0; while (!vis.empty()) { int f = *vis.begin(); vis.erase(f); ret++; q.push(f); while (!q.empty()) { int t = q.front(); q.pop(); for(int i = 0; i < edge[t].size(); i++){ if (vis.find(edge[t][i]) != vis.end()) { cout << "find: " << t << ", " << edge[t][i] << endl; q.push(edge[t][i]); vis.erase(edge[t][i]); } } } } output(ret, 0); return 0; }