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: import sys
  import collections
  
  N, M = map(int, sys.stdin.readline().strip().split())
  pw = list(map(int, sys.stdin.readline().strip().split()))
  es = {}
  eps = {}
  pes = {}
  for i in range(N):
      pes[i] = set()
  
  for i in range(M):
      p0, p1, w = map(int, sys.stdin.readline().strip().split())
      p0 = p0 - 1  # 0開始にする
      p1 = p1 - 1
      # 点から直接つながっている辺の情報の追加
      pes[p0].add(i)
      pes[p1].add(i)
      es[i] = [p0, p1, w]
      # 辺から直接つながっている点の情報の追加
      eps[i] = set([p0, p1])
  
  # print("辺情報、始点終点ウェイト {}".format(es))
  # print("辺情報、直接つながる点 {}".format(eps))
  # print("点情報、直接つながる辺 {}".format(pes))
  
  
  def countW(e):
      # print(e)
      p0 = es[e][0]
      p1 = es[e][1]
      # たどった辺の情報
      e1 = set([e])
      while True:
          # 辺をとる
          e2 = (pes[p0] | pes[p1]) - e1  # set演算
          # 新しい辺がない場合
          if len(e2) == 0:
              break
          e1 = e2 | e1
      # print(e1)
      pall = set()
      for ei in e1:
          # eの分も入る
          # print(eps[ei])
          pall = pall | eps[ei]
      # print(pall)
      # ウェイトの計算
      w = 0
      for pi in pall:
          w += pw[pi]
      return w
  
  
  # print(countW(0))
  
  survived = set(range(M))
  # print(survived)
  
  while True:
      flag = False
      snew = survived.copy()
      # print(snew)
      for i in survived:
          # 辺の重みのほうが大きかったらTrue
          if countW(i) < es[i][2]:
              flag = True
              snew.discard(i)
              """
        そういう辺は全部消す。消したところで、点の重みの和が減っていくので、
        だめだった他の辺が大丈夫になるようなことはない。
        """
              pes[es[i][0]].discard(i)
              pes[es[i][1]].discard(i)
      # print(snew)
      survived = snew
      # すべて大丈夫だったら
      if flag == False:
          break
      if len(survived) <= 0:
          break
  
  ans = M - len(survived)
  print(ans)
  
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"}]