#region Header #!/usr/bin/env python3 # from typing import * import sys import io import heapq def input(): return sys.stdin.readline()[:-1] sys.setrecursionlimit(1000000) #endregion # _INPUT = """5 6 4 5 8 # 1 2 2 # 2 5 3 # 2 4 1 # 3 4 3 # 1 3 2 # 3 5 1 # """ # sys.stdin = io.StringIO(_INPUT) def dijkstra(G, N, start): dist = [10**20 for _ in range(N)] hq = [] heapq.heappush(hq, (0, start)) dist[start] = 0 while hq: d, p = heapq.heappop(hq) if d > dist[p]: continue for (p1, w1) in G[p]: d1 = dist[p] + w1 if d1 < dist[p1]: dist[p1] = d1 heapq.heappush(hq, (dist[p1], p1)) return dist def main(): N, M, P, Q, T = map(int, input().split()) P -= 1 Q -= 1 G = [list() for _ in range(N)] for _ in range(M): a, b, c = map(int, input().split()) G[a-1].append((b-1, c)) G[b-1].append((a-1, c)) dist_0 = dijkstra(G, N, 0) dist_P = dijkstra(G, N, P) dist_Q = dijkstra(G, N, Q) if dist_0[P] + dist_P[Q] + dist_0[Q] <= T: print(T) else: max_t = -1 for i in range(N): for j in range(i, N): # 0 -> i -> P -> j -> 0 # 0 -> i -> Q -> j -> 0 t_total1 = dist_0[i] + dist_P[i] + dist_P[j] + dist_0[j] t_total2 = dist_0[i] + dist_Q[i] + dist_Q[j] + dist_0[j] if t_total1 <= T and t_total2 <= T: t = T - max(dist_P[i] + dist_P[j], dist_Q[i] + dist_Q[j]) max_t = max(max_t, t) print(max_t) if __name__ == '__main__': main()