n,m,p,q,t=map(int,input().split()) abc=[list(map(int,input().split())) for _ in range(m)] p,q=p-1,q-1 g=[[] for _ in range(n)] for a,b,c in abc: a,b=a-1,b-1 g[a].append([b,c]) g[b].append([a,c]) inf=float('inf') from0=[inf]*n fromp=[inf]*n fromq=[inf]*n from0[0]=0 todo=[[0,0]] from heapq import heappop,heappush while todo: d,v=heappop(todo) if from0[v]d+nd: from0[nv]=d+nd heappush(todo,[d+nd,nv]) fromp[p]=0 todo=[[0,p]] from heapq import heappop,heappush while todo: d,v=heappop(todo) if fromp[v]d+nd: fromp[nv]=d+nd heappush(todo,[d+nd,nv]) fromq[q]=0 todo=[[0,q]] from heapq import heappop,heappush while todo: d,v=heappop(todo) if fromq[v]d+nd: fromq[nv]=d+nd heappush(todo,[d+nd,nv]) # 別行動しない0->p->q->0 # vで別行動をはじめる。 # 0->v->p->v->0 # 0->v->q->v->0 # vで別行動をはじめるとする。v->p,q最短距離で向かい、再びvで合流するのが最適か # N<=2000sなのでO(N^2)?ひっかけ? tmp=from0[p]+fromp[q]+fromq[0] #print(from0) #print(fromp) #print(fromq) if tmp<=t: print(t) exit() ans=-1 for v in range(n): tmp=from0[v]*2+max(fromp[v],fromq[v])*2 if tmp<=t: ans=max(ans,t-max(fromp[v],fromq[v])*2) print(ans)