#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long int ll; typedef pair P; template struct FibonacciHeap{ struct Node{ val_t val; key_t key; int deg; Node *par, *ch, *l, *r; bool mark; Node(val_t val, key_t key):val(val), key(key), par(nullptr), ch(nullptr), l(this), r(this), mark(false), deg(0){} }; vector vr; Node *min_node; int sz; FibonacciHeap():sz(0), min_node(nullptr){} bool empty(){ return sz==0; } void concat(Node *&s, Node *t){ if(!t) return; if(!s){ s=t; return; } s->r->l=t->l; t->l->r=s->r; s->r=t; t->l=s; } void delete_node(Node *t){ t->l->r=t->r; t->r->l=t->l; t->l=t; t->r=t; } Node *push(val_t val, key_t key){ sz++; Node *t=new Node(val, key); concat(min_node, t); if(!min_node || t->valval) min_node=t; return t; } void link(Node *t, Node *c){ t->deg++; delete_node(c); c->par=t; concat(c, t->ch); if(!t->ch) t->ch=c; } pair pop(){ sz--; pair ret=make_pair(min_node->val, min_node->key); auto y=(min_node->r==min_node)?nullptr:min_node->r; delete_node(min_node); auto x=min_node->ch; if(x) x->par=nullptr; concat(x, y); min_node=nullptr; if(!x){ return ret; } auto x1=x; do{ x1->par=nullptr; if(!min_node || x1->valval) min_node=x1; x1=x1->r; }while(x1!=x); x1=min_node; int last=-1; do{ auto xr=x1->r; while(x1->degdeg]){ auto x2=vr[x1->deg]; vr[x1->deg]=nullptr; if(x2==min_node || x1->val>x2->val){ swap(x1, x2); } link(x1, x2); } if(x1->deg>=vr.size()) vr.resize(x1->deg+1); vr[x1->deg]=x1; last=max(last, x1->deg); x1=xr; }while(x1!=min_node); for(int i=0; i<=last; i++) vr[i]=nullptr; return ret; } void decrease(Node *t, val_t d){//t->val=d t->val=d; if(!t->par){ if(!min_node || t->valval) min_node=t; return; } if(t->par->val<=d) return; while(t->par){ auto tp=t->par; t->par->deg--; t->par->ch=((t->r==t)?nullptr:t->r); delete_node(t); t->par=nullptr; concat(min_node, t); if(!min_node || t->valval) min_node=t; if(!tp->mark){ tp->mark=1; break; } t=tp; } } }; const ll INF=1e16; int n, m, p, q; vector

g[2001]; void dijkstra(int s, ll d[2001]){ fill(d, d+n, INF); d[s]=0; FibonacciHeap que; using node=FibonacciHeap::Node; vector v(n); v[s]=que.push(0, s); while(!que.empty()){ auto p1=que.pop(); int x=p1.second; for(int j=0; jd[x]+q1.first){ d[y]=d[x]+q1.first; if(!v[y]) v[y]=que.push(d[y], y); else que.decrease(v[y], d[y]); } } } } int main() { ll t; cin>>n>>m>>p>>q>>t; p--; q--; for(int i=0; i>a>>b>>c; a--; b--; g[a].push_back(P(c, b)); g[b].push_back(P(c, a)); } ll d1[2001], dp[2001], dq[2001]; dijkstra(0, d1); dijkstra(p, dp); dijkstra(q, dq); if(t=d1[p]+dp[q]+d1[q]){ cout<t) continue; ans=max(ans, t-dm); } } cout<