#include #include #include #include #include #include using namespace std; typedef int point; typedef int weight; struct edge{ point dest; weight w; edge(){} edge(point dest,weight w):dest(dest),w(w){} }; namespace std{ bool operator > (const edge &lhs, const edge &rhs) { return lhs.w > rhs.w; } }; typedef vector edges; typedef map graph; typedef map potential; const int infty=1<<28; potential dijkstra(graph &g,const point &st) { potential pot; priority_queue > toBeProcessed; toBeProcessed.push(edge(st,0)); while ( !toBeProcessed.empty() ) { edge e= toBeProcessed.top(); toBeProcessed.pop(); point &p=e.dest; if ( pot.count(p)!=0 ) continue; pot[p]=e.w; edges& es=g[p]; for ( int i=0 ; i>nodes>>rods>>src>>dest1>>dest2 && nodes>0 ) { graph fg; graph bg; for ( int i=0 ; i>from>>to>>c; fg[from].push_back(edge(to,c)); bg[to].push_back(edge(from,c)); } potential fp(dijkstra(fg,src)); potential bp1(dijkstra(bg,dest1)); potential bp2(dijkstra(bg,dest2)); int record=infty; for ( int i=1 ; i<=nodes ; i++ ) { if ( fp.count(i) && bp1.count(i) && bp2.count(i) ) record=min(record, fp[i]+bp1[i]+bp2[i]); } cout<