import sys from heapq import heappop as hpp, heappush as hp def dijkstra(N, s, Edge): inf = 10**10 dist = [inf] * N Q = [(0, s)] decided = set() for _ in range(N): while True: dn, vn = hpp(Q) if vn not in decided: decided.add(vn) dist[vn] = dn break for vf, df in Edge[vn]: if vf not in decided: hp(Q, (dn + df, vf)) return dist N, M, P, Q, T = map(int, input().split()) P -= 1 Q -= 1 Edge = [[] for _ in range(N)] for _ in range(M): a, b, c = map(int, sys.stdin.readline().split()) a -= 1 b -= 1 Edge[a].append((b, c)) Edge[b].append((a, c)) dist0 = dijkstra(N, 0, Edge) distP = dijkstra(N, P, Edge) distQ = dijkstra(N, Q, Edge) ans = -1 for i in range(N): for j in range(N): t = dist0[i] + dist0[j] + max(distP[i]+distP[j], distQ[i]+distQ[j]) if t > T: continue ans = max(ans, dist0[i] + dist0[j] + T - t) if dist0[P] + distP[Q] + dist0[Q] <= T: ans = T print(ans)