from heapq import * def dijkstra(g,start): n = len(g) M = 1<<32 INF = 1<<60 dist = [INF]*n #startからの最短距離 dist[start] = 0 q = [start] #(そこまでの距離、点) while q: dv,v = divmod(heappop(q),M) if dist[v] < dv: continue for to, cost in g[v]: if dv + cost < dist[to]: dist[to] = dv + cost heappush(q, (dist[to]*M+to)) return dist def solve(x): dist = dijkstra(g,x) res = 0 direct = 1<<60 for i in range(n): if t[i] == 0: continue res += t[i]*2*dist[i] direct = min(direct,dL[i] - dist[i]) return res+direct import sys input = sys.stdin.readline n,m,L = map(int,input().split()) L -= 1 *t, = map(int,input().split()) if t.count(0) == n-1: print(0) exit() g = [[] for _ in range(n)] for _ in range(m): a,b,c = map(int,input().split()) g[a-1].append((b-1, c)) g[b-1].append((a-1, c)) dL = dijkstra(g,L) ans = 10**18 for i in range(n): ans = min(ans,solve(i)) print(ans)