import heapq import sys input = sys.stdin.readline def main(): N,M,L = map(int,input().split()) L -= 1 lst = list(map(int,input().split())) lsg = [[] for i in range(N)] for i in range(M): a,b,c = map(int,input().split()) a -= 1 b -= 1 lsg[a].append((b,c)) lsg[b].append((a,c)) #if sum(lst) == 1: # print(0) # return INF = 10**10 distL = [INF]*(N) used = [False]*(N) distL[L] = 0 h = [(0,L)] while h: c,x = heapq.heappop(h) if used[x]: continue used[x] = True for j,cos in lsg[x]: if used[j]: continue if distL[j] > distL[x]+cos: distL[j] = distL[x]+cos heapq.heappush(h, (distL[j],j)) ans = 10**18 for i in range(N): st = i distC = [INF]*(N) used = [False]*(N) distC[st] = 0 h = [(0,st)] while h: c,x = heapq.heappop(h) if used[x]: continue used[x] = True for j,cos in lsg[x]: if used[j]: continue if distC[j] > distC[x]+cos: distC[j] = distC[x]+cos heapq.heappush(h, (distC[j],j)) divmax = -INF sumcost = 0 for k in range(N): sumcost += distC[k]*lst[k]*2 if lst[k] >= 1 and divmax<(distC[k]-distL[k]): divmax = distC[k]-distL[k] if ans>(sumcost-divmax): ans = sumcost-divmax print(ans) main()