#include #include using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < (int)(n); i++) void solve() { ll n, m; cin >> n >> m; vector>> que(m); rep(i, m) { ll u, v, w; cin >> u >> v >> w; que[i] = {w, {u, v}}; } sort(que.rbegin(), que.rend()); ll q; cin >> q; vector> qs(q); rep(qi, q) { ll r; cin >> r; qs[qi] = {r, qi}; } sort(qs.begin(), qs.end()); atcoder::dsu dsu(n); ll now = n; vector ans(q); for (const auto [r, qi] : qs) { while (!que.empty() && que.back().first <= r) { auto [u, v] = que.back().second; que.pop_back(); if (!dsu.same(u, v)) { dsu.merge(u, v); now--; } } ans[qi] = now; } rep(qi, q) cout << ans[qi] << '\n'; } int main() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); int T = 1; for (int t = 0; t < T; t++) { solve(); } return 0; }