import sys from heapq import heappop, heappush input = sys.stdin.buffer.readline INF = 10**18 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 = tuple(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 = sum(T[x] * 2 * dist_all[x][target] for x in range(N)) m = max(dist_all[target][x] - dist_all[L][x] for x in range(N) if T[x] != 0) ans = min(ans, s - m) print(ans)