import sys def MI(): return map(int, sys.stdin.buffer.readline().split()) def LI(): return list(map(int, sys.stdin.buffer.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] inf = 10**16 import numpy as np from scipy.sparse.csgraph import dijkstra from scipy.sparse import csr_matrix n, m, l = MI() l -= 1 tt = LI() if tt.count(0) >= n-1: print(0) exit() e = np.array(LLI(m),dtype="i8").T g=csr_matrix((e[2],e[:2]-1),(n,n)) # print(g) dd=dijkstra(g,directed=False).astype("i8") ans = inf for g in range(n): mn = inf for s in range(n): if tt[s] == 0: continue cur = dd[l][s]-dd[s][g] if cur < mn: mn = cur mn += sum(tt[u]*dd[u][g] for u in range(n))*2 if mn < ans: ans = mn print(ans)