#region Header #!/usr/bin/env python3 # from typing import * import sys import io import math import collections import decimal import itertools import bisect 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 main(): N, M, P, Q, T = map(int, input().split()) P -= 1 Q -= 1 INF = 10**10 cost = [[INF] * N for _ in range(N)] for _ in range(M): a, b, c = map(int, input().split()) cost[a-1][b-1] = c cost[b-1][a-1] = c # ワーシャルフロイド for k in range(N): for i in range(N): for j in range(N): if cost[i][k] != INF and cost[k][j] != INF: cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]) if cost[0][P] + cost[P][Q] + cost[Q][0] <= T: print(T) else: max_t = -1 for i in range(N): for j in range(N): # 0 -> i -> P -> j -> 0 # 0 -> i -> Q -> j -> 0 t_total1 = cost[0][i] + cost[i][P] + cost[P][j] + cost[j][0] t_total2 = cost[0][i] + cost[i][Q] + cost[Q][j] + cost[j][0] if t_total1 <= T and t_total2 <= T: t = cost[0][i] + cost[j][0] + (T - max(t_total1, t_total2)) max_t = max(max_t, t) print(max_t) if __name__ == '__main__': main()