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