#include using namespace std; using ll = long long; const int INF = 1e9 + 10; const ll INFL = 4e18; struct DSU { DSU() = default; DSU(int n) { par = vector(n); sz = vector(n); for (int i = 0; i < n; i++) { par[i] = i; sz[i] = 1; } forest_count = n; } int find(int x) { if (par[x] == x) return x; return par[x] = find(par[x]); } void unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; if (sz[x] < sz[y]) swap(x, y); par[y] = x; sz[x] += sz[y]; forest_count--; } int size(int x) { return sz[find(x)]; } bool same(int x, int y) { return find(x) == find(y); } int count() { return forest_count; } vector> groups() { int n = par.size(); vector> res(n); for (int i = 0; i < n; i++) res[find(i)].push_back(i); res.erase(remove_if(res.begin(), res.end(), [&](const vector& v) { return v.empty(); }), res.end()); return res; } private: vector par, sz; int forest_count; }; int main() { int N, M; cin >> N >> M; vector> E; for (int i = 0; i < M; i++) { int a, b, c; cin >> a >> b >> c; E.push_back({c, a, b}); } int T; cin >> T; for (int i = 0; i < T; i++) { int r; cin >> r; E.push_back({r, INF, i}); } ranges::sort(E); DSU dsu(N); vector ans(T); for (auto [c, a, b] : E) { if (a == INF) { ans[b] = dsu.count(); } else { dsu.unite(a, b); } } for (int i = 0; i < T; i++) cout << ans[i] << '\n'; }