class Town: def __init__(self): self.T = None self.V = [] self.M = float('inf') N, M = map(int, input().split()) T = [Town() for _ in range(N)] for _ in range(M): a, b, c = map(int, input().split()) T[a-1].V.append((b-1, c)) T[b-1].V.append((a-1, c)) for i, t in enumerate(list(map(int, input().split()))): T[i].T = t q = [(0, 0, 0)] while len(q) > 0: i, m, p = q.pop(0) t = T[i] p += t.T m += t.T for j, c in t.V: nt = T[j] if T[j].M > m+c/p: T[j].M = m+c/p q.append((j, m+c/p, p)) print(int(T[N-1].M))