N,M,P,Q,T = map(int, input().split()) E = [[] for _ in range(N)] for _ in range(M): a,b,c = map(int, input().split()) E[a-1].append((c, b-1)) E[b-1].append((c, a-1)) import heapq def dijkstra(s): inf = 10**18 dist = [inf]*N dist[s] = 0 h = [] for e in E[s]: heapq.heappush(h, e) while h: temp = heapq.heappop(h) d = temp[0] v = temp[1] if dist[v] < d: continue dist[v] = d for e in E[v]: if dist[e[1]] < dist[v]+e[0]: continue heapq.heappush(h, (e[0]+d, e[1])) return dist dist_0 = dijkstra(0) dist_p = dijkstra(P-1) dist_q = dijkstra(Q-1) if dist_0[P-1]+dist_p[Q-1]+dist_q[0] <= T: ans = T elif dist_0[P-1]*2 > T or dist_0[Q-1]*2 > T: ans = -1 else: ans = 0 for i in range(N): if i == P-1 or i == Q-1: continue if (dist_0[i]+max(dist_p[i], dist_q[i]))*2 <= T: ans = max(ans, T-max(dist_p[i], dist_q[i])*2) print(ans)