from scipy.sparse import csr_matrix from scipy.sparse.csgraph import dijkstra import numpy as np import sys input = sys.stdin.buffer.readline sys.setrecursionlimit(10 ** 7) N, M, P, Q, T = map(int, input().split()) A, B, C = np.array([input().split() for _ in range(M)], dtype=np.int64).T G = csr_matrix((C, (A-1, B-1)), shape=(N, N)) path = (dijkstra(G, directed=False) + 0.01).astype(np.int64) # ぜんぶ2人で回る t = path[0][P-1] + path[P-1][Q-1] + path[Q-1][0] if t <= T: print(T) exit() ans = 0 same = path[0, :] toP = path[:, P-1] toQ = path[:, Q-1] time = 2 * (same + np.maximum(toP, toQ)) wait = np.maximum(0, T - time) if (time > T).all(): print(-1) exit() ans = (2 * same + wait)[time <= T].max() print(ans)