#include #include #define rep(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++) using namespace atcoder; using namespace std; typedef long long ll; int main() { int n, m; cin >> n >> m; vector> edges; rep(i, 0, m) { int a, b, c; cin >> a >> b >> c; edges.push_back({c, a, b}); } sort(edges.begin(), edges.end()); reverse(edges.begin(), edges.end()); int q; cin >> q; vector qs(q); rep(i, 0, q) cin >> qs[i]; auto qss = qs; sort(qss.begin(), qss.end()); map ans; dsu uf(n); int ns = n; for (auto q : qss) { while (!edges.empty() && get<0>(edges.back()) <= q) { auto [c, a, b] = edges.back(); edges.pop_back(); if (uf.same(a, b)) continue; ns--; uf.merge(a, b); } ans[q] = ns; } for (auto q : qs) { cout << ans[q] << '\n'; } }