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; using System.Threading; using System.Runtime.CompilerServices; 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=n-1; li=new List>[n+1]; b=new bool[n+1]; var c=new long[n+1][]; for(int i=1;i<=n;i++){ li[i]=new List>(); c[i]=Enumerable.Repeat(inf,s[1]).ToArray(); } for(int i=0;i=0;j--) {Fu(u[j]);} void Fu(int g) { z=Min(z+(v==0?0:al.Di(v,g)),c[g][i-1]+s[2]); c[g][i]=z+al.Di(g,q[i]); f=Min(f,c[g][i]); ba[g]=i; v=g; } for(int j = 1;j<=n;j++) { if(ba[j]!=i){c[j][i]=c[j][i-1]+d;} } } Console.WriteLine("{0}",f); } static void Fu(int a,int g){ b[a]=true; for(int i=0;i>[] li; private readonly int[] at,ix,l; public readonly int[] oy; private readonly long[] de; private readonly int[][] g; private int f=0; public Alca(List>[] li,bool bo,int r){ int n=li.Length,z=(n<<1)-3,m=z; this.li=li; at=new int[z]; ix=new int[n]; oy=new int[n]; de=new long[n]; if(bo){Fu1(r,1);} else{ for(int i = 1;i>1]+1; } for(int i=1,k=1;ib){(a,b)=(b,a);} int p=l[b-a]; return at[de[at[g[p][a]]](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