import sys input = sys.stdin.buffer.readline def main(): n, m, p, q, t = map(int, input().split()) p -= 1 q -= 1 edge = [[] for _ in range(n)] for i in range(m): a, b, c = map(int, input().split()) a, b = a-1, b-1 edge[a].append((c, b)) edge[b].append((c, a)) import heapq INF = 10**18 def dijkstra_heap(s, edge, n): d = [INF] * n used = [True] * n #True: not used d[s] = 0 used[s] = False edgelist = [] for e in edge[s]: heapq.heappush(edgelist,e) while len(edgelist): minedge = heapq.heappop(edgelist) if not used[minedge[1]]: continue v = minedge[1] d[v] = minedge[0] used[v] = False for e in edge[v]: if used[e[1]]: heapq.heappush(edgelist,(e[0]+d[v],e[1])) return d d1 = dijkstra_heap(0, edge, n) dp = dijkstra_heap(p, edge, n) dq = dijkstra_heap(q, edge, n) if d1[p]+dp[q]+d1[q] <= t: print(t) exit() if 2*d1[p]> t or 2*d1[q] > t: print(-1) exit() ans = -1 for r in range(n): temp = d1[r]+max(dp[r], dq[r]) temp *= 2 #print(r, temp) if temp <= t: temp2 = 2*d1[r]+t-temp ans = max(temp2, ans) print(ans) if __name__ == '__main__': main()