最短路径
Description
有n个城市(编号从1到n),个城市之间都有路连接,切这些路都是单向的。每条路都有相应的长度。各城市之间构成的路网不可能构成环状。没有一条路到达城市1,所有城市都能够到达城市n。城市n不能到达其它任何城市。
Input
第一行包含一个整数n,表示城市数目。
接下来包含n行,每行n个整数。第i行第j列的整数a[i][j]表示城市i和城市j的路径长度。
Output
第一行输出最短路径长度,形如minlong=最短路径长度值“”。
接下来的一行输出从第1个城市到第n个城市的最短路径上的所有城市。(详见样例)
Sample Input
10
0 2 5 1 0 0 0 0 0 0
0 0 0 0 12 14 0 0 0 0
0 0 0 0 6 10 4 0 0 0
0 0 0 0 13 12 11 0 0 0
0 0 0 0 0 0 0 3 9 0
0 0 0 0 0 0 0 6 5 0
0 0 0 0 0 0 0 0 10 0
0 0 0 0 0 0 0 0 0 5
0 0 0 0 0 0 0 0 0 2
0 0 0 0 0 0 0 0 0 0
Sample Output
minlong=19
1 3 5 8 10
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;
const int MAX_V=5e2+1;
int cost[MAX_V][MAX_V];
int used[MAX_V];
int d[MAX_V];
//记录前趋顶点
int pre[MAX_V];
int V,n;
//用dijkstra算法
void dijkstra(int s){
</