#include #include #define rep(i, n) for(long long i = 0; i < n; i++) #define ALL(v) (v).begin(), (v).end() using namespace std; using lint = long long; int main() { int n, m; cin >> n >> m; vector>> es(100010); rep(i, m) { int u, v, w; cin >> u >> v >> w; es[w].emplace_back(0, u, v); } int t; cin >> t; rep(i, t) { int r; cin >> r; es[r].emplace_back(1, i, -1); } rep(i, 100010) { sort(ALL(es[i])); } atcoder::dsu uf(n); int cnt = n; vector ans(t); rep(i, 100010) { rep(j, (int)es[i].size()) { if (get<0>(es[i][j]) == 0) { auto [type, u, v] = es[i][j]; if (!uf.same(u, v)) { uf.merge(u, v); cnt--; } } else { auto [type, id, hoge] = es[i][j]; ans[id] = cnt; } } } rep(i, t) { cout << ans[i] << endl; } }