using System; using System.Collections.Generic; using System.Collections; using System.Collections.Specialized; using System.Linq; using System.Text; using System.IO; using System.Reflection; using static System.Math; using System.Numerics; static class Program{ const int mod=(int)1e9+7; const long inf=long.MaxValue-1; static List>[] li; static bool[] b; static void Main(){ Sc sc=new Sc(); var s=sc.Ia; int n=s[0],m=s[1]; li=new List>[n+1]; var c=new long[n+1]; var d=new long[n+1]; var f=new long[n+1]; for(int i=1;i<=n;i++){ li[i]=new List>(); c[i]=d[i]=f[i]=inf; } for(int i=0;i(32); b=new bool[n+1]; pq.Push(new Rheap.Dt(0,s[2])); while(pq.cnt>0){ var e=pq.Dequeue; if(b[e.d]){continue;} b[e.d]=true; for(int i=0;ili[e.d][i].Item2+e.n){ pq.Push(new Rheap.Dt(li[e.d][i].Item2+e.n,li[e.d][i].Item1)); c[li[e.d][i].Item1]=li[e.d][i].Item2+e.n; } } } pq=new Rheap(32); b=new bool[n+1]; pq.Push(new Rheap.Dt(0,s[3])); while(pq.cnt>0){ var e=pq.Dequeue; if(b[e.d]){continue;} b[e.d]=true; for(int i=0;ili[e.d][i].Item2+e.n){ pq.Push(new Rheap.Dt(li[e.d][i].Item2+e.n,li[e.d][i].Item1)); d[li[e.d][i].Item1]=li[e.d][i].Item2+e.n; } } } pq=new Rheap(32); b=new bool[n+1]; pq.Push(new Rheap.Dt(0,1)); while(pq.cnt>0){ var e=pq.Dequeue; if(b[e.d]){continue;} b[e.d]=true; for(int i=0;ili[e.d][i].Item2+e.n){ pq.Push(new Rheap.Dt(li[e.d][i].Item2+e.n,li[e.d][i].Item1)); f[li[e.d][i].Item1]=li[e.d][i].Item2+e.n; } } } if(f[s[2]]+f[s[3]]+c[s[3]]<=s[4]){ Console.WriteLine(s[4]); return; } long ans=-1; for(int i = 1;i{ public class Dt{ public long n; public T d; public Dt(long n,T d){this.n=n;this.d=d;} public override string ToString()=>"d:"+d.ToString()+" n:"+n.ToString(); } private const int m=65; private long la=0; private Dt[][] bf; private int[] h; public int cnt=0; public Rheap(int max){ bf=new Dt[m][]; h=new int[m]; for(int i = 0;i0){ int p=0; for(int j = 1;jbf[i][j].n){p=j;} } la=bf[i][p].n; for(int j = 0;j(int n,Func f){var a=new T[n];for(int i=0;i(int n,Func f){var a=new T[n];for(int i=0;i(int n,Func f){var a=new T[n];for(int i=0;i(int n,Func f){var a=new T[n];for(int i=0;i