#include "bits/stdc++.h" using namespace std; typedef long long ll; typedef pairP; ll N, M, T; ll st[3] = {1, 0, 0}; vector

path[2020]; ll cost[3][2020]; int main(){ cin >> N >> M >> st[1] >> st[2] >> T; for(ll i = 0; i < M; i++){ ll a, b, c; cin >> a >> b >> c; path[a].push_back(P(b, c)); path[b].push_back(P(a, c)); } for(ll i = 0; i < 3; i++){ for(ll j = 0; j < 2020; j++)cost[i][j] = -1; priority_queue, greater

>Q; Q.push(P(0, st[i])); while(!Q.empty()){ ll idx = Q.top().second; ll cst = Q.top().first; Q.pop(); if(cost[i][idx] >= 0)continue; cost[i][idx] = cst; for(ll j = 0; j < path[idx].size(); j++){ ll nxt = path[idx][j].first; ll w = path[idx][j].second; if(cost[i][nxt] < 0){ Q.push(P(cst + w, nxt)); } } } } ll ans = -1; for(ll i = 1; i <= N; i++){ // cout << cost[0][i] << ", " << cost[1][i] << ", " << cost[2][i] << endl; if(T >= 2 * (cost[0][i] + cost[1][i] + cost[2][i])){ ans = T; } else if(T >= 2 * cost[0][i] + 2 * max(cost[1][i], cost[2][i])){ ans = max(ans, T - 2 * max(cost[1][i], cost[2][i])); } } if(T >= cost[0][st[1]] + cost[0][st[2]] + cost[1][st[2]])ans = T; cout << ans << endl; return 0; }