#include using namespace std; class UnionFind{ public: vector par,siz; void make(int N){ par.resize(N,-1); siz.resize(N,1); } int root(int x){ if(par.at(x) == -1) return x; else return par.at(x) = root(par.at(x)); } void unite(int u, int v){ u = root(u),v = root(v); if(u == v) return; if(siz.at(u) < siz.at(v)) swap(u,v); par.at(v) = u; siz.at(u) += siz.at(v); } bool issame(int u, int v){ if(root(u) == root(v)) return true; else return false; } }; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int N,M; cin >> N >> M; vector>> Rs(100001); for(int i=0; i> u >> v >> w; Rs.at(w).push_back({u,v}); } int T; cin >> T; vector> Ts(T); for(int i=0; i> Ts.at(i).first,Ts.at(i).second = i; sort(Ts.begin(),Ts.end()); vector answer(T); int ans = N,nowr = 0; UnionFind Z; Z.make(N); for(auto [r,pos] : Ts){ while(nowr <= r){ for(auto [u,v] : Rs.at(nowr)){ if(Z.issame(u,v)) continue; ans--; Z.unite(u,v); } nowr++; } answer.at(pos) = ans; } for(auto a : answer) cout << a << endl; }