import heapq INF = 10**18 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 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() d1 = dijkstra(l, g) ans = INF for i in range(n): d2 = dijkstra(i, g) s = 0 for j in range(n): s += d2[j]*T[j] for j in range(n): if T[j] == 0: continue temp = 2*s+d1[j]-d2[j] ans = min(ans, temp) print(ans)