#!/usr/bin/env python3.8 # %% import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import numpy as np from scipy.sparse.csgraph import dijkstra from scipy.sparse import csr_matrix # %% N, M, L = map(int, readline().split()) T = np.array(readline().split(), np.int64) ABC = np.array(read().split(), np.int64) A = ABC[::3] - 1 B = ABC[1::3] - 1 C = ABC[2::3] # %% if np.count_nonzero(T > 0) <= 1: print(0) exit() # %% graph = csr_matrix((N, N)) for a, b, c in zip(A, B, C): if graph[a, b] == 0 or graph[a, b] > c: graph[a, b] = c dist = dijkstra(graph, directed=False) # %% dist = (dist + .5).astype(np.int64) cost = (dist * T[None, :]).sum(axis=1) * 2 diff = -dist + dist[L - 1][None, :] diff[:, T == 0] += 10 ** 12 cost = cost[:, None] + diff print(cost.min())