The main idea: to give a map, to find the shortest point of 1 to N, the difference is that for each edge, in addition to the source point and cost, there is an additional point C, if you go to this edge before the C point, the cost will be reduced to another value p. If the shortest circuit does not exist, the output impossible.
The Floyd-warshall algorithm is used to determine the connectivity, and the additional C and P are ignored at this time.
Then use the Dijkstra algorithm, with D[i][s] to indicate at point I and through the S set of points of the shortest, will each d[i][s] as a point, with the Dijkstra algorithm calculation.
#include <stdio.h> #include <stdlib.h> #include <vector> #include <queue>using namespace std; const int inf= (1<<29); struct edge{int from;int to;int sit;int dis1;int dis2;}; struct Heapnode{int di;int num1;int num2;bool operator< (const Heapnode j) Const{return di>j.di;}}; Edge E[15];int d[15][1100];int con[15][15];int use[15][1100];int m,n;void Dijkstra (int s); void Floyd_warshall (void); int main (void) {int i,j,u,p,ans;while (scanf ("%d%d", &n,&m) ==2) {for (i=1;i<=n;i++) {for (j=1;j<=n;j++) { con[i][j]= (i==j)? 1:0;}} for (i=1;i<=m;i++) {scanf ("%d%d%d%d%d", &e[i].from,&e[i].to,&e[i].sit,&e[i].dis2,&e[i]. DIS1); con[e[i].from][e[i].to]=1;} Floyd_warshall (); if (con[1][n]==0) {printf ("impossible\n");} Else{dijkstra (1); ans=inf;u= (1<< (n-1));p = (1<<n); for (j=0;j<p;j++) {if (D[n][j|u|1]<ans) {Ans=d[n] [J|u|1];}} printf ("%d\n", ans);}} return 0;} void Dijkstra (int s) {int i,j,u,v,p;heapnode h;priority_queue
POJ 3411-paid Roads (state compression +dijkstra algorithm +floyd-warshall algorithm)