#include using namespace std; using ll = long long; #define ALL(v) v.begin(),v.end() #define dbg(x) cerr << #x << ": " << (x) << endl; struct UnionFind { UnionFind(int n) : par(n), rank(n, 1) { iota(par.begin(), par.end(), 0); } // 頂点xの根ノード int root(int x) { if (par[x] == x) return x; return par[x] = root(par[x]); } // 結合 bool unite(int x, int y) { x = root(x); y = root(y); if (x == y) return false; if (rank[x] > rank[y]) swap(x,y); if (rank[x] == rank[y]) ++rank[y]; par[x] = y; return true; } // 頂点xと頂点yが同じ集合ならtrue bool same(int x, int y) { return root(x) == root(y); } vector> groups() { vector> gr(par.size()); for (int v = 0; v < par.size(); ++v) { gr[root(v)].push_back(v); } vector> res; for (int v = 0; v < (int)par.size(); ++v) { if (gr[v].size()) res.push_back(gr[v]); } return res; } vector par, rank; }; int n,m; vector>> e(1e5 + 1); int t; vector q; int main() { cin >> n >> m; for (int i = 0; i < m; ++i) { int a,b,c; cin >> a >> b >> c; e[c].emplace_back(a,b); } cin >> t; q.resize(t); for (int i = 0; i < t; ++i) cin >> q[i]; vector idx(t); iota(ALL(idx), 0); sort(ALL(idx), [&](int i, int j) { return q[i] < q[j]; }); UnionFind uf(n); vector ans(t); int cnt = n; int end = 0; for (int qi : idx) { for (int i = end; i <= q[qi]; ++i) { for (auto [u,v] : e[i]) { if (uf.unite(u,v)) { --cnt; } } } end = q[qi]; ans[qi] = cnt; } for (int i : ans) { cout << i << '\n'; } }