Because there are multiple starting points, so what?
1: Reverse build (personal feeling trouble)
2: Building a super starting point
I used the second, simple rough, that is, a new starting point (0), he and all the topic of the beginning of the link, and the distance is 0, and then the template walk
#include <iostream> #include <cstring> #include <vector> #include <algorithm> #define INF 1< <28#define maxn 1010using namespace Std;int n,m,e;vector<int>mapp[maxn];int vaule[maxn][maxn];int VISIT[MAXN ];void Init () {for (int i=0;i<=n;i++) mapp[i].clear (); memset (Vaule,0,sizeof (Vaule));} void input () {for (int i=0;i<m;i++) {int x,y,z;cin>>x>>y>>z;if (!vaule[x][y]) {Mapp[x].push_back ( y); vaule[x][y]=z;} else Vaule[x][y]=min (vaule[x][y],z);} cin>>m;for (int i=0;i<m;i++) {int x;cin>>x;mapp[0].push_back (x);}} int DJ () {int D[maxn];fill (d,d+1+n,inf), Fill (visit,visit+1+n,0);d [0]=0;while (!visit[e]) {//for (int i=0;i<=n;i++) cout<<d[i]<< "";//cout<<endl;int v=-1;for (int i=0;i<=n;i++) {if (!visit[i]&& | D[I]<D[V]) v=i;} Cout<<v<<endl;if (v==-1| | D[v]==inf) return-1;visit[v]=1;for (int i=0;i<mapp[v].size (); i++) {int x=mapp[v][i];d [X]=min (d[x],d[v]+vaule[v][ X]);//cout<<x<< "~" <<d[x]<<endl;}} return d[e];} int main () {Cin.sync_with_stdio (false), while (cin>>n>>m>>e) {init (); input (); Cout<<dj () < <endl;} return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
HDU 2680 Choose the best route