import sys import pypyjit import itertools import heapq import math from collections import deque, defaultdict import bisect input = sys.stdin.readline sys.setrecursionlimit(10 ** 6) pypyjit.set_param('max_unroll_recursion=-1') def index_lt(a, x): 'return largest index s.t. A[i] < x or -1 if it does not exist' return bisect.bisect_left(a, x) - 1 def index_le(a, x): 'return largest index s.t. A[i] <= x or -1 if it does not exist' return bisect.bisect_right(a, x) - 1 def index_gt(a, x): 'return smallest index s.t. A[i] > x or len(a) if it does not exist' return bisect.bisect_right(a, x) def index_ge(a, x): 'return smallest index s.t. A[i] >= x or len(a) if it does not exist' return bisect.bisect_left(a, x) class Dijkstra: def __init__(self, N, E, inf=1 << 50): self.N = N self.E = E self.inf = inf def cost_from(self, s): C = [self.inf] * self.N C[s] = 0 h = [(0, s)] visited = set() while len(h) > 0: _, v = heapq.heappop(h) if v in visited: continue visited.add(v) for c, dest in self.E[v]: if C[dest] > C[v] + c: C[dest] = C[v] + c heapq.heappush(h, (C[dest], dest)) return C N, M, P, Q, T = map(int, input().split()) P -= 1 Q -= 1 E = [[] for _ in range(N)] for _ in range(M): a, b, c = map(int, input().split()) a -= 1 b -= 1 E[a].append((c, b)) E[b].append((c, a)) solver = Dijkstra(N, E) C0 = solver.cost_from(0) Cp = solver.cost_from(P) Cq = solver.cost_from(Q) if C0[P] + Cp[Q] + Cq[0] <= T: print(T) exit() ans = -1 for i in range(N): for j in range(N): t = C0[i] + max(Cp[i] + Cp[j], Cq[i] + Cq[j]) + C0[j] if t <= T: ans = max(ans, C0[i] + C0[j] + (T - t)) print(ans)