DJ the shortest path algorithm of the Slavic

Source: Internet
Author: User

#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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.