import sys from heapq import heappop, heappush input = sys.stdin.buffer.readline INF = 10**9 def dijkstra(N, G, s): dist = [INF] * N que = [(0, s)] dist[s] = 0 while que: c, v = heappop(que) if dist[v] < c: continue for t, cost in G[v]: if dist[v] + cost < dist[t]: dist[t] = dist[v] + cost heappush(que, (dist[t], t)) return dist N, M, L = map(int, input().split()) L -= 1 T = list(map(int, input().split())) G = [[] for _ in range(N)] for _ in range(M): a, b, c = map(int, input().split()) a -= 1 b -= 1 G[a].append((b, c)) G[b].append((a, c)) dist_all = [] for source in range(N): dist_all.append(dijkstra(N, G, source)) ans = INF for target in range(N): s = 0 for x in range(N): s += T[x] * 2 * dist_all[x][target] m = 0 for x in range(N): if T[x] == 0: continue m = max(m, dist_all[target][x] - dist_all[L][x]) ans = min(ans, s - m) print(ans)