//核心代码
#include<string.h>
#include<stdio.h>
typedef struct ArcCell
{
int adj;//相邻接的城市序号
}ArcCell;//定义边的类型
typedef struct VertexType
{
int number;//城市序号
char *city;//城市名称
}VertexType;//定义顶点的类型
typedef struct
{
VertexType vex[25];//图中的顶点,即为城市
ArcCell arcs[25][25];//图中的边,即为城市间的距离
int vexnum,arcnum;//顶点数,边数
}MGraph;//定义图的类型
MGraph G;//把图定义为全局变量
int P[25][25];
long int D[25];
//其他函数见光盘
void ShortestPath(num)//最短路径函数
int num;
{
int v,w,i,t;
int final[25];
int min;
for(v=0;v<25;++v)
{
final[v]=0;D[v]=G.arcs[num][v].adj;
for(w=0;w<25;++w)
P[v][w]=0;
if(D[v]<20000)
{
P[v][num]=1;P[v][v]=1;
}
}
D[num]=0;final[num]=1;
for(i=0;i<25;++i)
{
min=20000;
for(w=0;w<25;++w)
if(!final[w])
if(D[w]<min)
{
v=w;min=D[w];
}
final[v]=1;
for(w=0;w<25;++w)
if(!final[w]&&((min+G.arcs[v][w].adj)<D[w]))
{
D[w]=min+G.arcs[v][w].adj;
for(t=0;t<25;t++)
P[w][t]=P[v][t];
P[w][w]=1;
}
}
}