import heapq class Graph: def __init__(self,V,edges=None,graph=None,directed=False,weighted=False,inf=float("inf")): self.V=V self.directed=directed self.weighted=weighted self.inf=inf if graph!=None: self.graph=graph """ self.edges=[] for i in range(self.V): if self.weighted: for j,d in self.graph[i]: if self.directed or not self.directed and i<=j: self.edges.append((i,j,d)) else: for j in self.graph[i]: if self.directed or not self.directed and i<=j: self.edges.append((i,j)) """ else: self.edges=edges self.graph=[[] for i in range(self.V)] if weighted: for i,j,d in self.edges: self.graph[i].append((j,d)) if not self.directed: self.graph[j].append((i,d)) else: for i,j in self.edges: self.graph[i].append(j) if not self.directed: self.graph[j].append(i) def Dijkstra(self,s,route_restoration=False): dist=[self.inf]*self.V dist[s]=0 queue=[(0,s)] if route_restoration: parents=[None]*self.V while queue: dx,x=heapq.heappop(queue) if dist[x]dx+dy: dist[y]=dx+dy if route_restoration: parents[y]=x heapq.heappush(queue,(dist[y],y)) if route_restoration: return dist,parents else: return dist N,M,P,Q,T=map(int,input().split()) edges=[] for m in range(M): a,b,c=map(int,input().split()) a-=1;b-=1 edges.append((a,b,c)) G=Graph(N,edges=edges,weighted=True) P-=1;Q-=1 dist0=G.Dijkstra(0) distP=G.Dijkstra(P) distQ=G.Dijkstra(Q) if dist0[P]+distP[Q]+distQ[0]<=T: ans=T else: ans=-1 for x in range(N): for y in range(N): dP=dist0[x]+distP[x]+distP[y]+dist0[y] dQ=dist0[x]+distQ[x]+distQ[y]+dist0[y] if dP<=T and dQ<=T: ans=max(ans,T-max(distP[x]+distP[y],distQ[x]+distQ[y])) print(ans)