import sys readline = sys.stdin.readline N,M,P,Q,T = map(int,readline().split()) P -= 1 Q -= 1 G = [[] for i in range(N)] for _ in range(M): a,b,c = map(int,readline().split()) G[a - 1].append([b - 1, c]) G[b - 1].append([a - 1, c]) INF = 1 << 60 import heapq as hq def get_dist_from(x): dist = [INF] * N q = [] hq.heappush(q, (0, x)) while q: d, v = hq.heappop(q) if dist[v] != INF: continue dist[v] = d for child, c in G[v]: if dist[child] != INF: continue hq.heappush(q, (d + c, child)) return dist dist_from_0 = get_dist_from(0) dist_from_P = get_dist_from(P) dist_from_Q = get_dist_from(Q) if dist_from_0[P] + dist_from_Q[P] + dist_from_0[Q] <= T: print(T) exit(0) ans = -1 for v in range(N): # vまで一緒に行動して、以後別行動パターン time = dist_from_0[v] + max(dist_from_Q[v] + dist_from_Q[0], dist_from_P[v] + dist_from_P[0]) if time <= T: # 一緒にいる時間 stay = (T - time) + dist_from_0[v] ans = max(ans, stay) # vまで一緒に行動、P,Qを訪れて、またvに合流するパターン time = dist_from_0[v] * 2 + max(dist_from_P[v] * 2, dist_from_Q[v] * 2) if time <= T: stay = T - max(dist_from_P[v] * 2, dist_from_Q[v] * 2) ans = max(ans, stay) print(ans)