#include <stdio.h>#include<windows.h>inta[Ten][Ten];intarc[Ten];//record the endpoint of an arcintcost[Ten];//record the distance from the starting point to the current I pointintuse[Ten];//record whether the current I point is being usedvoidPathintN) { for(intI=0; i<n;i++) {//Initial assignment default all points starting at point 0, where the path prefix point is 0,use[i] is not usedcost[i]=a[0][i]; Arc[i]=0; Use[i]=0; } use[0]=1;//default 0 is the starting point and 0 is added to the shortest path for(intI=1; i<n;i++) {//The default final path must be a connected graph intj=1;//record the current loop subscript intk=0;//record the shortest point subscript of the unknown point path currently known intmin=65535;//Comparison value default 65535 is unreachable while(j<N) { if(use[j]==0&&cost[j]>0&&cost[j]<min) {//Judging Condition: The current point is not available and the path is the shortest path endk=J; Min=Cost[i]; } J++; } Use[k]=1;//The path that marks the point to the starting point is knownprintf"%d,%d\n", K,cost[k]); for(intI=0; i<n;i++) {printf ("%d", Cost[i]); } printf ("\ n"); System ("Pause"); for(intt=0; t<n;t++){ //Update the length of the path from the point to the remaining point by a known new calculated shortest path, condition: up to and not used, the updated value is smaller than the current value if(a[k][t]>0&&a[k][t]<65535&&use[t]==0&&a[k][t]+cost[k]<Cost[t]) {Cost[t]=a[k][t]+Cost[k]; Arc[t]=K; } } } for(intI=0; i<n;i++) {printf ("%d", Arc[i]); }}intMain () {intN; scanf ("%d",&N); for(intI=0; i<n;i++){ for(intj=0; j<n;j++) {scanf ("%d",&A[i][j]); }} path (n);}
DJ the shortest path algorithm of the Slavic