import sys def MI(): return map(int, sys.stdin.buffer.readline().split()) def LI(): return list(map(int, sys.stdin.buffer.readline().split())) inf = 10**16 from heapq import * def dijk(u): hp = [] dist = [inf]*n dist[u] = 0 heappush(hp, (0, u)) while hp: d, u = heappop(hp) if d > dist[u]: continue for v, c in to[u]: nd = d+c if nd >= dist[v]: continue dist[v] = nd heappush(hp, (nd, v)) return dist n, m, l = MI() l -= 1 tt = LI() if tt.count(0) >= n-1: print(0) exit() to = [[] for _ in range(n)] for _ in range(m): a, b, c = MI() a, b = a-1, b-1 to[a].append((b, c)) to[b].append((a, c)) dd = [] for u in range(n): dd+=dijk(u) # print(dd) ans = inf for g in range(n): mn = inf for s in range(n): if tt[s] == 0: continue cur = dd[l*n+s]-dd[s*n+g] if cur < mn: mn = cur mn += sum(tt[u]*dd[u*n+g] for u in range(n))*2 if mn < ans: ans = mn print(ans)