Sample Input:
4 5 0 3
0 1 1 20
1 3 2 30
0 3 4 10
0 2 2 20
2 3 1 20
Sample Output:
0 2 3 3 40
题解:
相对于普通的Dijsktra,将parent[]
数组,变为了vector<int> pre[]
,这样就可以根据目标节点,递归遍历其所有的最短路径,最终找到价格最小的那条路径
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
struct cmp{
bool operator()(pair<int,int> &a,pair<int,int> &b){
return a.second > b.second;
}
};
const int MAXV = 510;
const int INF = 100000;
int n,m,s,d,G[MAXV][MAXV],G_value[MAXV][MAXV];
int dis[MAXV];
vector<int> pre[MAXV];
vector<int> short_path,temp_short_path;
int opValue = INF,value = INF;
priority_queue