Really the words died early, the topic looked two times only then to understand.
According to the requirements of the construction side, from the ' Z ' start to run the shortest possible.
Program CODEVS1079;varA:Array[0.. +,0.. +] ofLongint; D:Array[0.. +] ofLongint; PD:Array[0.. +] ofBoolean; Flag:Array[0.. +] ofBoolean; B:Array[0..10000] ofLongint; Ch,space,ch2,ans:char; I,j,m,x,min:longint;procedureSPFA (s:longint);varI,j,l,r,u,v:longint;beginFillchar (pd,sizeof (PD), false); Fillchar (b,sizeof (b),0); Fillchar (d,sizeof (d), $7f); L:=1; r:=1; Pd[s]:=true; B[l]:=s; d[s]:=0; whileL<=r Do beginu:=B[l]; forV:=ord ('A') toOrd'Z') Do if(a[u,v]<10000) and(D[u]+a[u,v]<d[v]) Then beginD[v]:=d[u]+A[u,v]; if notPD[V] Then beginInc (R); B[R]:=v; PD[V]:=true; End; End; Inc (L); Pd[u]:=false; End;End;beginFillchar (flag,sizeof (flag), false); Fillchar (A,sizeof (a), $7f); READLN (m); fori:=1 toM Do beginreadln (ch,space,ch2,space,x); ifX>a[ord (CH), Ord (CH2)] Thencontinue; A[ord (CH), Ord (CH2)]:=x; A[ord (CH2), Ord (CH)]:=x; Flag[ord (CH)]:=true; Flag[ord (CH2)]:=true; End; Min:=Maxlongint; SPFA (Ord ('Z')); forI:=ord ('A') toOrd'Y') Do ifFlag[i] Then ifD[i]<min Then beginans:=chr (i); Min:=D[i]; End; Writeln (ans,' ', min);End.
CODEVS1079 Home (Shortest way)