import heapq INF = 1<<60 def dijkstra(s, edge): n = len(edge) dist = [INF]*n dist[s] = 0 edgelist = [] heapq.heappush(edgelist,(dist[s], s)) while edgelist: minedge = heapq.heappop(edgelist) if dist[minedge[1]] < minedge[0]: continue v = minedge[1] for e in edge[v]: if dist[e[1]] > dist[v]+e[0]: dist[e[1]] = dist[v]+e[0] heapq.heappush(edgelist,(dist[e[1]], e[1])) return dist import sys import io, os input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline def main(): n, m, l = map(int, input().split()) l -= 1 T = list(map(int, input().split())) g = [[] for i in range(n)] for i in range(m): a, b, c = map(int, input().split()) a, b = a-1, b-1 g[a].append((c, b)) g[b].append((c, a)) cnt = 0 for i in range(n): if T[i] != 0: cnt += 1 if cnt == 1: print(0) exit() D = [dijkstra(i, g) for i in range(n)] ans = INF for i in range(n): s=sum(T[j]*D[i][j] for j in range(n))*2 if s: s+=min(D[l][j]-D[i][j] for j in range(n) if T[j]) ans=min(ans,s) print(ans) if __name__ == '__main__': main()