import sys

sys.setrecursionlimit(10**6)



N, M = list(map(int, input().split()))

*X, = list(map(int, input().split()))

E = []

for i in range(M):

    a, b, y = list(map(int, input().split()))

    E.append((y, a-1, b-1))

E.sort()



*p, = list(range(N))

Z = [0]*M

A = X[:]

C = [-1]*N

def root(x):

    if x == p[x]:

        return x

    p[x] = y = root(p[x])

    return y



def unite(x, y):

    px = root(x); py = root(y)

    if px == py:

        return 0

    if px < py:

        p[py] = px

        A[px] += A[py]

    else:

        p[px] = py

        A[py] += A[px]

    return 1



G = [None for i in range(M)]



ans = 0

for i, (y, a, b) in enumerate(E):

    pa = root(a); pb = root(b)

    ca = C[pa]; cb = C[pb]

    if unite(a, b):

        pa = root(a)

        Z[i] = 1

        C[pa] = i

        #print(">", i, pa, pb, A[pa], y)

        if A[pa] < y:

            G[i] = []

            if ca != -1:

                G[i].append(ca)

            if cb != -1:

                G[i].append(cb)

    else:

        if A[pa] < y:

            G[i] = []

            if ca != -1:

                G[i].append(ca)

            C[pa] = i



sx = sum(X)

#print(Z)



if N > 1:

    from collections import deque

    que = deque()

    if sx < E[C[0]][0]:

        que.append(C[0])

    #print(G, C)

    while que:

        v = que.popleft()

        #print(v)

        if G[v] is not None:

            ans += 1

            for w in G[v]:

                que.append(w)

print(ans)
from collections import deque

import operator



N, M = list(map(int, input().split()))

*X, = list(map(int, input().split()))

E = []

for i in range(M):

    a, b, y = list(map(int, input().split()))

    E.append((y, a-1, b-1))

E.sort()

*Y, = list(map(operator.itemgetter(0), E))



*p, = list(range(N))

def root(x):

    if x == p[x]:

        return x

    p[x] = y = root(p[x])

    return y



A = X[:]

def unite(x, y):

    px = root(x); py = root(y)

    if px == py:

        return 0

    if px < py:

        p[py] = px

        A[px] += A[py]

    else:

        p[px] = py

        A[py] += A[px]

    return 1



G = [[] for i in range(M)]

B = [0]*M

C = [-1]*N



ans = 0

for i, (y, a, b) in enumerate(E):

    pa = root(a); pb = root(b)

    ca = C[pa]; cb = C[pb]

    if unite(a, b):

        if ca != -1:

            G[i].append(ca)

        if cb != -1:

            G[i].append(cb)

        pa = root(a)

    else:

        if ca != -1:

            G[i].append(ca)

    B[i] = A[pa]

    C[pa] = i



if N > 1 and sum(X) < E[C[0]][0]:

    que = deque()

    que.append(C[0])

    while que:

        v = que.popleft()

        if B[v] < Y[v]:

            ans += 1

            que.extend(G[v])

print(ans)
import sys

sys.setrecursionlimit(10**6)
N, M = list(map(int, input().split()))
(*X,) = list(map(int, input().split()))
E = []
for i in range(M):
    a, b, y = list(map(int, input().split()))
    E.append((y, a - 1, b - 1))
E.sort()
(*p,) = list(range(N))
Z = [0] * M
A = X[:]
C = [-1] * N


def root(x):
    if x == p[x]:
        return x
    p[x] = y = root(p[x])
    return y


def unite(x, y):
    px = root(x)
    py = root(y)
    if px == py:
        return 0
    if px < py:
        p[py] = px
        A[px] += A[py]
    else:
        p[px] = py
        A[py] += A[px]
    return 1


G = [None for i in range(M)]
ans = 0
for i, (y, a, b) in enumerate(E):
    pa = root(a)
    pb = root(b)
    ca = C[pa]
    cb = C[pb]
    if unite(a, b):
        pa = root(a)
        Z[i] = 1
        C[pa] = i
        # print(">", i, pa, pb, A[pa], y)
        if A[pa] < y:
            G[i] = []
            if ca != -1:
                G[i].append(ca)
            if cb != -1:
                G[i].append(cb)
    else:
        if A[pa] < y:
            G[i] = []
            if ca != -1:
                G[i].append(ca)
            C[pa] = i
sx = sum(X)
# print(Z)
if N > 1:
    from collections import deque

    que = deque()
    if sx < E[C[0]][0]:
        que.append(C[0])
    # print(G, C)
    while que:
        v = que.popleft()
        # print(v)
        if G[v] is not None:
            ans += 1
            for w in G[v]:
                que.append(w)
print(ans)

from collections import deque
import operator

N, M = list(map(int, input().split()))
(*X,) = list(map(int, input().split()))
E = []
for i in range(M):
    a, b, y = list(map(int, input().split()))
    E.append((y, a - 1, b - 1))
E.sort()
(*Y,) = list(map(operator.itemgetter(0), E))
(*p,) = list(range(N))


def root(x):
    if x == p[x]:
        return x
    p[x] = y = root(p[x])
    return y


A = X[:]


def unite(x, y):
    px = root(x)
    py = root(y)
    if px == py:
        return 0
    if px < py:
        p[py] = px
        A[px] += A[py]
    else:
        p[px] = py
        A[py] += A[px]
    return 1


G = [[] for i in range(M)]
B = [0] * M
C = [-1] * N
ans = 0
for i, (y, a, b) in enumerate(E):
    pa = root(a)
    pb = root(b)
    ca = C[pa]
    cb = C[pb]
    if unite(a, b):
        if ca != -1:
            G[i].append(ca)
        if cb != -1:
            G[i].append(cb)
        pa = root(a)
    else:
        if ca != -1:
            G[i].append(ca)
    B[i] = A[pa]
    C[pa] = i
if N > 1 and sum(X) < E[C[0]][0]:
    que = deque()
    que.append(C[0])
    while que:
        v = que.popleft()
        if B[v] < Y[v]:
            ans += 1
            que.extend(G[v])
print(ans)

-import sys +from collections import deque +import operator -sys.setrecursionlimit(10**6) +(*Y,) = list(map(operator.itemgetter(0), E)) -Z = [0] * M -A = X[:] -C = [-1] * N + + +A = X[:] -G = [None for i in range(M)] +G = [[] for i in range(M)] +B = [0] * M +C = [-1] * N +        if ca != -1: +            G[i].append(ca) +        if cb != -1: +            G[i].append(cb) -        Z[i] = 1 -        C[pa] = i -        # print(">", i, pa, pb, A[pa], y) -        if A[pa] < y: -            G[i] = [] -            if ca != -1: -                G[i].append(ca) -            if cb != -1: -                G[i].append(cb) -        if A[pa] < y: -            G[i] = [] -            if ca != -1: -                G[i].append(ca) -            C[pa] = i -sx = sum(X) -# print(Z) -if N > 1: -    from collections import deque - +        if ca != -1: +            G[i].append(ca) +    B[i] = A[pa] +    C[pa] = i +if N > 1 and sum(X) < E[C[0]][0]: -    if sx < E[C[0]][0]: -        que.append(C[0]) -    # print(G, C) +    que.append(C[0]) -        # print(v) -        if G[v] is not None: +        if B[v] < Y[v]: -            for w in G[v]: -                que.append(w) +            que.extend(G[v])