MOD = 10 ** 9 + 7 INF = 10 ** 12 import sys sys.setrecursionlimit(100000000) dy = (-1,0,1,0) dx = (0,1,0,-1) from itertools import permutations from heapq import heapify,heappop,heappush def dijkstra(G,s = 0): #sを始点とした最短経を求める n = len(G) dist = [INF] * n dist[s] = 0 q = [(0,s)] heapify(q) while q: d,v = heappop(q) if dist[v] < d: continue for e,cost in G[v]: if dist[e] > dist[v] + cost: dist[e] = dist[v] + cost heappush(q,(dist[e],e)) return dist def main(): n,m,p,q,t = map(int,input().split()) p -= 1 q -= 1 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)) d0 = dijkstra(G) dp = dijkstra(G,p) dq = dijkstra(G,q) if d0[p] + dp[q] + dq[0] <= t: print(t) return ans = -1 for i in range(n): if 2 * (d0[i] + dp[i] + dq[i]) <= t: print(t) return if 2 * (max(dp[i],dq[i]) + d0[i]) <= t: ans = max(ans,t - 2 * max(dp[i],dq[i])) print(ans) if __name__ =='__main__': main()