from heapq import heappush, heappop from collections import defaultdict def dijkstra(start): distance = [10 ** 18 for _ in range(N)] distance[start] = 0 priority_queue = [] for i in range(N): heappush(priority_queue, (distance[i], i)) while len(priority_queue) > 0: current_dist, current_node = heappop(priority_queue) if distance[current_node] < current_dist: continue for next_node, w in adj_dict[current_node]: if distance[next_node] > distance[current_node] + w: distance[next_node] = distance[current_node] + w heappush(priority_queue, (distance[next_node], next_node)) return distance N, M, P, Q, T = map(int, input().split()) adj_dict = defaultdict(list) for _ in range(M): a_i, b_i, c_i = map(int, input().split()) adj_dict[a_i-1].append((b_i-1, c_i)) adj_dict[b_i-1].append((a_i-1, c_i)) distance = [dijkstra(i) for i in range(N)] ans = -10 ** 18 if distance[0][P-1] + distance[P-1][Q-1] + distance[Q-1][0] <= T: print(T) exit() for m1 in range(N): for m2 in range(N): if distance[0][m1] + max(distance[m1][P-1]+distance[P-1][m2], distance[m1][Q-1]+distance[Q-1][m2]) + distance[m2][0] <= T: ans = max(ans, distance[0][m1] + distance[m2][0] + T - (distance[0][m1] + max(distance[m1][P-1]+distance[P-1][m2], distance[m1][Q-1]+distance[Q-1][m2]) + distance[m2][0])) if ans == -10 ** 18: print(-1) else: print(ans)