#dijkstra? from heapq import heappop, heappush, heapify n,m,l=map(int,input().split()) T=list(map(int,input().split())) graph=[[] for _ in range(n+1)] dist=[[10**10]*(n+1) for _ in range(n+1)] for _ in range(m): a,b,c=map(int,input().split()) graph[a].append((c,b)) graph[b].append((c,a)) def dij(s,graph,dist): used=[False]*(n+1) used[s]=True dist[s][s]=0 edgelist=[] for es in graph[s]: heappush(edgelist,es) while edgelist: kyori,ten=heappop(edgelist) if used[ten]==True: continue dist[s][ten]=kyori used[ten]=True for es in graph[ten]: if used[es[1]]==False: heappush(edgelist,(es[0]+dist[s][ten], es[1])) return dist ans=[] for i in range(1,n+1): dist=dij(i, graph,dist) for first in range(1,n+1): a=dist[l][first] for p in range(1,n+1): temp=a temp+=dist[first][p] for j in range(n): cnt=T[j] if j == first-1: cnt=max(0,cnt-1) temp+=2*cnt*dist[p][j+1] ans.append(temp) print(min(ans))