#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)] if sum(T)==1: print(0) else: 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=10**20 for i in range(1,n+1): dist=dij(i, graph,dist) for p in range(1,n+1): ouhuku=0 for j in range(n): ouhuku+=2*T[j]*dist[p][j+1] for first in range(1,n+1): if T[first-1]==0: continue if first==p: temp=ouhuku+dist[l][first] else: temp=ouhuku+dist[l][first]+dist[first][p]-(dist[p][first]*2) ans=min(ans,temp) print(ans)