output_description: Find the minimum number of edges that need to be removed.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N M
      X_1 X_2 ... X_N
      A_1 B_1 Y_1
      A_2 B_2 Y_2
      :
      A_M B_M Y_M
attempt: N, M = map(int, input().split())
  (*X,) = map(int, input().split())
  ABY = [list(map(int, input().split())) for _ in [0] * M]
  
  ABY = [(a - 1, b - 1, y) for a, b, y in ABY]
  ABY.sort(key=lambda x: x[2])
  
  import sys
  
  sys.setrecursionlimit(10**7)
  
  
  class UnionFind:
      def __init__(self, N, X):
          self.Parent = list(range(N))
          self.Weight = X[:]
  
      def get_Parent(self, n):
          if self.Parent[n] == n:
              return n
          p = self.get_Parent(self.Parent[n])
          self.Parent[n] = p
          return p
  
      def get_Weight(self, n):
          n = self.get_Parent(n)
          return self.Weight[n]
  
      def merge(self, x, y):
          x = self.get_Parent(x)
          y = self.get_Parent(y)
          if x != y:
              self.Parent[y] = x
              self.Weight[x] += self.Weight[y]
          return
  
      def is_united(self, x, y):
          return self.get_Parent(x) == self.get_Parent(y)
  
  
  # 最小全域木を作る
  U0 = UnionFind(N, [0] * N)
  E = [0] * M
  Et = [[] for _ in [0] * N]
  for i, aby in enumerate(ABY):
      a, b, y = aby
      if U0.is_united(a, b):
          E[i] = -1  # -1 : 最小全域木に使わない
          continue
      U0.merge(a, b)
      Et[a].append((b, y, i))
      Et[b].append((a, y, i))
  
  import heapq
  
  hpush = heapq.heappush
  hpop = heapq.heappop
  
  U_final = UnionFind(N, X)
  for i, aby in enumerate(ABY):
      if E[i] != 0:
          continue
      a, b, y = aby
  
      if U_final.get_Weight(a) + U_final.get_Weight(b) >= y:
          U_final.merge(a, b)
          E[i] = 3  # 3 : 本決め使用
          continue
  
      hq = [(y, i)]
      U_tmp = UnionFind(N, X)
  
      while hq:
          y1, i1 = hpop(hq)
          a, b, _ = ABY[i1]
          E[i1] = 1  # 1 : 仮決めの仮定
          U_tmp.merge(a, b)
          q = [a, b]
          while q:
              j = q.pop()
              for k, y2, ek in Et[j]:
                  if E[ek] == 4:
                      continue
                  if U_tmp.is_united(j, k):
                      continue
                  if E[ek] == 3:
                      U_tmp.merge(j, k)
                      q.append(k)
                      continue
                  if y2 > y1:
                      hpush(hq, (y2, ek))
                      continue
                  E[ek] = 2  # 2 : 仮決め従属で使用
                  U_tmp.merge(j, k)
          if U_tmp.get_Weight(a) >= y1:
              break
      else:
          for j in range(M):
              if E[j] == 1:
                  E[j] = 4
              elif E[j] == 2:
                  E[j] = 0
          continue
      for j in range(M):
          if E[j] == 1 or E[j] == 2:
              a, b, _ = ABY[j]
              E[j] = 3
              U_final.merge(a, b)
  
  for j in range(M):
      if E[j] != -1:
          continue
      a, b, y = ABY[j]
      if not U_final.is_united(a, b):
          E[j] = 4
      elif U_final.get_Weight(a) >= y:
          E[j] = 3
      else:
          E[j] = 4
  
  print(E.count(4))
  
problem_description: Statement
  
  There is a connected undirected graph with N vertices and M edges. The
  vertices are numbered 1 to N, and the edges are numbered 1 to M. Also, each of
  these vertices and edges has a specified weight. Vertex i has a weight of X_i;
  Edge i has a weight of Y_i and connects Vertex A_i and B_i.
  
  We would like to remove zero or more edges so that the following condition is
  satisfied:
  
    * For each edge that is not removed, the sum of the weights of the vertices in the connected component containing that edge, is greater than or equal to the weight of that edge.
  
  Find the minimum number of edges that need to be removed.
samples: [{"input": "4 4\n    2 3 5 7\n    1 2 7\n    1 3 9\n    2 3 12\n    3 4 18", "output": "2\n    \n\nAssume that we removed Edge 3 and 4. In this case, the connected component\ncontaining Edge 1 contains Vertex 1, 2 and 3, and the sum of the weights of\nthese vertices is 2+3+5=10. The weight of Edge 1 is 7, so the condition is\nsatisfied for Edge 1. Similarly, it can be seen that the condition is also\nsatisfied for Edge 2. Thus, a graph satisfying the condition can be obtained\nby removing two edges.\n\nThe condition cannot be satisfied by removing one or less edges, so the answer\nis 2.\n\n* * *"}, {"input": "6 10\n    4 4 1 1 1 7\n    3 5 19\n    2 5 20\n    4 5 8\n    1 6 16\n    2 3 9\n    3 6 16\n    3 4 1\n    2 6 20\n    2 4 19\n    1 2 9", "output": "4\n    \n\n* * *"}, {"input": "10 9\n    81 16 73 7 2 61 86 38 90 28\n    6 8 725\n    3 10 12\n    1 4 558\n    4 9 615\n    5 6 942\n    8 9 918\n    2 7 720\n    4 7 292\n    7 10 414", "output": "8"}]