HDU 2066 Dijstra Reactor optimization

Source: Internet
Author: User

Yes, there's a wide search.

#include <cstdio> #include <iostream> #include <queue> #include <vector> #define MAXN 1001# Define INF 9999999using namespaceStd;structVEC//This is where the adjacency matrix is used to compare wasted space so with the adjacency table here is the weighted graph so with the structure of the composition{intPoint,Cost;friendBOOLoperator< (VEC A,VEC b) {returnA.Cost>B.Cost; }};intT,S,D,Sta[Maxn],En[Maxn],Dis[Maxn];Vector<Vec>Fuck[Maxn];voidInit(){Fill(Dis,Dis+Maxn+1,Inf); for(intI=1;I<=Maxn;I++)Fuck[I].Clear();}voidDij(intSs){Priority_queue<Vec>Q;Dis[Ss]=0;VEC Temp;Temp.Point=Ss;Temp.Cost=0;Q.Push(Temp); while(!Q.Empty())//Breadth update every time you remove the nearest point from the starting point {Temp=Q.Top();Q.Pop();intV=Temp.Point;if(Dis[V]<Temp.Cost)Continue; for(intI=0;I<Fuck[V].Size();I++)//Update the distance of points around vertices {VEC ret=Fuck[V][I];if(Dis[Ret.Point]>Dis[V]+Ret.Cost)//If the distance from the adjacent point can be updated {Dis[Ret.Point]=Dis[V]+Ret.Cost;Ret.Cost=Dis[Ret.Point];Q.Push(Ret); } } }}intMain(){ while(Cin>>T>>S>>D) {Init();//cout<<t<<s<<d<<endl; while(T--) {intA,B,C;Cin>>A>>B>>C;VEC Temp;Temp.Cost=C;Temp.Point=B;Fuck[A].Push_back(Temp);Temp.Point=A;Fuck[B].Push_back(Temp); } for(intI=1;I<=S;I++)Cin>>Sta[I]; for(intI=1;I<=D;I++)Cin>>En[I];intmins=0; for(intI=1;I<=S;I++) {Dij(Sta[I]);mins=Inf; for(intJ=1;J<=D;J++)mins=Min(mins,Dis[En[J]]); }cout<<mins<<Endl; }return0;}

HDU 2066 Dijstra Reactor optimization

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.