void dijkstra(MGraph G){
int count=0;
int dist[MaxVertexNum];
int path[MaxVertexNum];
int visit[MaxVertexNum];
visit[0]=1;
path[0]=0;
dist[0]=0;
count++;
for (int i = 1; i <G.vexnum ; ++i) {
visit[i]=0;
path[i]=0;
dist[i]=G.Edge[0][i];
}
while (count< G.vexnum){
int min=INF;
int p;
for (int i = 1; i < G.vexnum; ++i) {
if (visit[i] == 0 && dist[i] < min){
min=dist[i];
p=i;
}
}
visit[p]=1;
count++;
for (int i = 1; i < G.vexnum; i++) {
if (visit[i] == 0 && (dist[p] + G.Edge[p][i] < dist[i])){
dist[i]=dist[p]+G.Edge[p][i];
path[i]=p;
}
}
}
for (int i = 0; i < G.vexnum; ++i) {
printf("%d ",dist[i]);
}
for (int i = 0; i < G.vexnum; ++i) {
printf("%d ",path[i]);
}
}
int main() {
MGraph G;
for (int i = 0; i < 6; i++) {
for (int j = 0; j < 6; j++){
if(i==j){
G.Edge[i][j] = 0;
} else{
G.Edge[i][j] = INF;
}
}
}
G.vexnum = 6;
G.Edge[0][4] =4;
G.Edge[0][1] =5;
G.Edge[1][3] =9;
G.Edge[1][2] =2;
G.Edge[2][4] =6;
G.Edge[3][0] =2;
G.Edge[4][3] =7;
G.Edge[4][1] =6;
G.Edge[4][5] =5;
G.Edge[5][2] =2;
dijkstra(G);
}