import sys input = sys.stdin.readline from heapq import heappop,heappush N,M,L=map(int,input().split()) T=list(map(int,input().split())) L-=1 E=[[] for i in range(N)] for i in range(M): a,b,c=map(int,input().split()) a-=1 b-=1 E[a].append((b,c)) E[b].append((a,c)) D=[[1<<60]*N for i in range(N)] for i in range(N): D[i][i]=0 Q=[(0,i)] while Q: #print(Q) dis,ind=heappop(Q) #print(D[i][ind]) if D[i][ind]!=dis: continue for to,length in E[ind]: if D[i][to]>dis+length: D[i][to]=dis+length heappush(Q,(D[i][to],to)) ANS=1<<63 for i in range(N): score=0 for j in range(N): score+=T[j]*D[i][j]*2 for j in range(N): if T[j]>0: score+=D[L][j]-D[i][j] ANS=min(ANS,score) score-=D[L][j]-D[i][j] print(ANS)