from heapq import heappop, heappush INF = float('inf') def dijkstra(s, n): dist = [INF] * n hq = [(0, s)] # (distance, node) dist[s] = 0 seen = [False] * n while hq: dis, v = heappop(hq) if dist[v] < dis: continue seen[v] = True for to, cost in G[v]: if seen[to] == False and dist[v] + cost < dist[to]: dist[to] = dist[v] + cost heappush(hq, (dist[to], to)) return dist N, M, P, Q, T = map(int, input().split()) G = [list() for _ in range(N)] for i in range(M): a, b, c = map(int, input().split()) a-=1;b-=1 G[a].append((b,c)) G[b].append((a,c)) dis_0 = dijkstra(0,N) dis_p = dijkstra(P-1,N) dis_q = dijkstra(Q-1,N) if max(dis_p[0]*2,dis_q[0]*2)>T: exit(print(-1)) if 2*min(dis_p[0],dis_q[0])+2*dis_p[Q-1]<=T or dis_p[0]+dis_q[0]+dis_p[Q-1]<=T: exit(print(T)) res = 0 for i in range(N): for j in range(N): if dis_0[i]+dis_0[j]+max(dis_p[i]+dis_p[j],dis_q[i]+dis_q[j])<=T: res = max(res,T-max(dis_p[i]+dis_p[j],dis_q[i]+dis_q[j])) print(res)