from heapq import heappop, heappush def dijkstra(start, dist, path): candidate = [(0, start)] while candidate: cost, i = heappop(candidate) if cost > dist[i]: continue for c, j in path[i]: if cost+c >= dist[j]: continue dist[j] = cost+c heappush(candidate, (cost+c, j)) inf = 10**18+1 n, m, l= map(int, input().split(" ")) t = list(map(int, input().split(" "))) EDGES = [set() for _ in range(n)] for i in range(m): a, b, c = [int(x)-1 for x in input().split(" ")] c += 1 EDGES[a].add((c, b)) EDGES[b].add((c, a)) ans = 10**18+1 to2 = [inf]*n to2[l - 1] = 0 dijkstra(l - 1, to2, EDGES) for i in range(n): to_ = [inf]*n to_[i] = 0 dijkstra(i, to_, EDGES) w = 0 if i == (l - 1): for j in range(n): w += (to_[j] * t[j]) w = 2 * w else: if t[l - 1] > 0: w1 = to_[l - 1] w2 = 0 for j in range(n): w2 += (to_[j] * t[j] * 2) w2 -= (to_[l - 1] * 2) w = w1 + w2 else: w1 = 0 w2 = 0 for j in range(n): w1 = 0 w2 = 0 if t[j] > 0: w1 = to2[j] w1 += to_[j] for k in range(n): w2 += (to_[k] * t[k] * 2) w2 -= (to_[j] * 2) w = w1 + w2 ans = min(ans, w) ans = min(ans, w) print(ans)