from collections import defaultdict import numpy as np from scipy.sparse.csgraph import dijkstra from scipy.sparse import csr_matrix N, M, L = map(int, input().split()) L -= 1 # 0-indexed T = np.array(list(map(int, input().split())), dtype=np.int64) nonzero = np.nonzero(T)[0] d = defaultdict(lambda: 2 * 10 ** 6) for _ in range(M): a, b, c = map(int, input().split()) a -= 1 b -= 1 d[(a, b)] = min(d[(a, b)], c) frm, to, length = [], [], [] for (a, b), c in d.items(): frm.append(a) to.append(b) length.append(c) matr = csr_matrix((length, (frm, to)), shape=(N, N)) way = dijkstra(matr, directed=False).astype(np.int64) ans = np.inf for target in range(N): tmp = np.sum(way[target] * 2 * T) first = np.max(way[target][nonzero] - way[L][nonzero]) tmp -= first ans = min(ans, tmp) print(ans)