using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static int[] NList => ReadLine().Split().Select(int.Parse).ToArray(); static int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray(); public static void Main() { Solve(); } static void Solve() { var c = NList; var (n, m) = (c[0], c[1]); var map = NArr(m); var t = NN; var r = NList; if (n == 0) { WriteLine(string.Join("\n", Enumerable.Repeat(0, t))); return; } Array.Sort(map, (l, r) => l[2].CompareTo(r[2])); var pos = 0; var sub = new int[100001]; var uf = new UnionFindTree(n); var count = n; for (var i = 0; i < sub.Length; ++i) { while (pos < m && map[pos][2] <= i) { if (uf.Unite(map[pos][0], map[pos][1])) --count; ++pos; } sub[i] = count; } var ans = new int[t]; for (var i = 0; i < t; ++i) ans[i] = sub[r[i]]; WriteLine(string.Join("\n", ans)); } class UnionFindTree { int[] roots; public UnionFindTree(int size) { roots = new int[size]; for (var i = 0; i < size; ++i) roots[i] = -1; } public int GetRoot(int a) { if (roots[a] < 0) return a; return roots[a] = GetRoot(roots[a]); } public bool IsSameTree(int a, int b) { return GetRoot(a) == GetRoot(b); } public bool Unite(int a, int b) { var x = GetRoot(a); var y = GetRoot(b); if (x == y) return false; if (-roots[x] < -roots[y]) { var tmp = x; x = y; y = tmp; } roots[x] += roots[y]; roots[y] = x; return true; } public int GetSize(int a) { return -roots[GetRoot(a)]; } } }