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; static List>[] li; static bool[] b; static long[] c; static int[] ca; static long f=0,p,sum=0; static void Main(){ Sc sc=new Sc(); var s=sc.Ia; int n=s[0],m=s[1]; li=new List>[n+1]; b=new bool[n+1]; c=new long[n+1]; var h=new long[n+1]; ca=sc.Ia2; for(int i=1;i<=n;i++){ li[i]=new List>(); c[i]=long.MaxValue; sum+=ca[i]; } for(int i=0;i(32); pq.Push(new Rheap.Dt(0,s[2])); c[s[2]]=0; while(pq.cnt>0){ var e=pq.Dequeue; if(b[e.d]){continue;} b[e.d]=true; if(ca[e.d]==sum){ Console.WriteLine(0); return; } 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; } } } long ans=long.MaxValue; for(int j = 1;j<=n;j++) { h=new long[n+1]; b=new bool[n+1]; p=int.MinValue; f=0; pq=new Rheap(32); pq.Push(new Rheap.Dt(1,j)); h[j]=0; while(pq.cnt>0){ var e=pq.Dequeue; if(b[e.d]){continue;} if(ca[e.d]>0){ p=Max(p,e.n-1-c[e.d]); f+=(e.n-1)*ca[e.d]*2; } 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)); h[li[e.d][i].Item1]=li[e.d][i].Item2+e.n; } } } ans=Min(ans,f-p); } Console.WriteLine("{0}",ans); } } public class Rheap{ 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