#include "bits/stdc++.h" using namespace std; #define int long long #define FOR(i, a, b) for(int i=(a);i<(b);i++) #define RFOR(i, a, b) for(int i=(b-1);i>=(a);i--) #define REP(i, n) for(int i=0; i<(n); i++) #define RREP(i, n) for(int i=(n-1); i>=0; i--) #define REP1(i, n) for(int i=1; i<=(n); i++) #define RREP1(i, n) for(int i=(n); i>=1; i--) #define ALL(a) (a).begin(),(a).end() #define UNIQUE_SORT(l) sort(ALL(l)); l.erase(unique(ALL(l)), l.end()); #define CONTAIN(a, b) find(ALL(a), (b)) != (a).end() #define out(...) printf(__VA_ARGS__) int dxy[] = {0, 1, 0, -1, 0}; void solve(); signed main() { #if DEBUG std::ifstream in("input.txt"); std::cin.rdbuf(in.rdbuf()); #endif cin.tie(0); ios::sync_with_stdio(false); solve(); return 0; } /*================================*/ #if DEBUG #define SIZE 5 #else #define SIZE 2222 #endif int N,M,P,Q,T; typedef pair Edge; typedef pair I; vector< vector > E; int DP[3][SIZE]; void dijkstra(int a, int s) { auto dp = DP[a]; REP(i,SIZE) dp[i]=LONG_LONG_MAX; priority_queue, greater> que; dp[s]=0; que.push(*new I(0,s)); while(que.size()) { I i = que.top(); que.pop(); if (i.first > dp[i.second]) continue; for (auto e:E[i.second]) { int c = i.first + e.second; if (dp[e.first] > c) { dp[e.first] = c; que.push(*new I(c, e.first)); } } } } void solve() { cin>>N>>M>>P>>Q>>T; P--, Q--; int a,b,c; E.resize(N); REP(i,M) { cin>>a>>b>>c; a--,b--; E[a].push_back(*new Edge(b,c)); E[b].push_back(*new Edge(a,c)); } dijkstra(0, 0); dijkstra(1, P); dijkstra(2, Q); if ((DP[0][P] + DP[1][Q] + DP[2][0]) <= T) { cout << T << endl; return; } int ans = -1; REP(i,N)REP(j,N) { int t0 = DP[0][i] + DP[1][i] + DP[1][j] + DP[0][j]; int t1 = DP[0][i] + DP[2][i] + DP[2][j] + DP[0][j]; int t = max(t0, t1); if (t > T) continue; int d = max(DP[1][i] + DP[1][j], DP[2][i] + DP[2][j]); ans = max(ans, T-d); } cout << ans << endl; }