#include using namespace std; void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); } #include using namespace atcoder; int main() { fast_io(); int n, m; cin >> n >> m; vector> edges; for (int i = 0; i < m; i++) { int u, v, w; cin >> u >> v >> w; edges.push_back({w, u, v}); } sort(edges.begin(), edges.end()); dsu uf(n); int cur = 0; int components = n; vector ans(1e5 + 1, n); for (auto [w, u, v] : edges) { if (uf.same(u, v)) continue; components--; ans[w] = components; uf.merge(u, v); } for (int i = 1; i <= 1e5; i++) { if (ans[i] == n) ans[i] = ans[i - 1]; } int t; cin >> t; for (; t--;) { int r; cin >> r; cout << ans[r] << '\n'; } }