#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; using Pll = pair; using Pii = pair; constexpr ll MOD = 1000000007; constexpr long double EPS = 1e-10; constexpr int dyx[4][2] = { { 0, 1}, {-1, 0}, {0,-1}, {1, 0} }; constexpr int MAX_N = 2000; vector< vector > edges(MAX_N); class Dijkstra { public: ll d[MAX_N]; priority_queue< Pll, vector, greater > que; ll start = -1; Dijkstra(ll start): start(start) { fill(d, d+MAX_N, 1LL<<60); d[start] = 0; que.push(Pll(0, start)); while(!que.empty()){ Pll v = que.top(); que.pop(); if(d[v.second] < v.first) continue; for(Pll e: edges[v.second]){ if(d[e.first] > d[v.second] + e.second){ d[e.first] = d[v.second] + e.second; que.push(Pll(d[e.first], e.first)); } } } } ll get(ll x) { return d[x]; } }; int main() { int n,m,p,q; ll t; cin >> n >> m >> p >> q >> t; --p; --q; int a,b; ll c; for(int i=0;i> a >> b >> c; --a; --b; edges[a].emplace_back(b, c); edges[b].emplace_back(a, c); } Dijkstra d_0 = Dijkstra(0), d_p = Dijkstra(p), d_q = Dijkstra(q); ll ans = -1LL; if(d_0.get(p) + d_p.get(q) + d_q.get(0) <= t) { ans = t; } else { for(int r=0;r