#include using namespace std; int par[200020]; int siz[200020]; int gs; void init(int N) { gs = N; iota(par, par + N, 0); fill(siz, siz + N, 1); } int root(int v) { return par[v] = (v == par[v] ? v : root(par[v])); } int merge(int a, int b) { a = root(a); b = root(b); if (a == b) return 0; if (siz[a] < siz[b]) swap(a, b); par[b] = a; siz[a] += siz[b]; return 1; } int main () { int N, M; cin >> N >> M; init(N); std::vector> eg(M); for (auto& [w, u, v] : eg) { cin >> u >> v >> w; } int Q; cin >> Q; int fl = 0; vector R(Q); for (auto& r : R) cin >> r; vector ID(Q); iota(ID.begin(), ID.end(), 0); sort(ID.begin(), ID.end(), [&](int i, int j) {return R[i] < R[j];}); vector ans(Q); for (auto& i : ID) { int r = R[i]; while (fl < M && get<0>(eg[fl]) <= r) { fl ++; gs -= merge(get<1>(eg[fl]), get<2>(eg[fl])); } ans[i] = gs; } for (auto& a : ans) { cout << a << endl; } }