CODEVS1079 Home (Shortest way)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.