Test instructions: Gives N, which represents n nodes.
To half the adjacency matrix, itself to itself the distance is 0, the side is bidirectional. When there is no direct edge connection between the two nodes, it is represented by X.
Ask for at least the time taken from the first node to all other nodes.
The only processing of this problem is to handle the adjacency matrix when the processing is first read as a string, and then processing the data into a data format.
Finally, the maximum value of the shortest path to all other nodes is output from the first node.
#include <stdio.h>#include<string.h>intN;Const intinf=99999999;intpho[ the][ the];Chartmp[ the][ +];BOOLvis[ the];intdis[ the];voidSolveintPOS) {Vis[pos]=1; for(intI=1; i<=n;i++) { if(!vis[i]&&pho[pos][i]+dis[pos]<Dis[i]) {Dis[i]=pho[pos][i]+Dis[pos]; } } intnext=inf; intminn=inf; for(intI=1; i<=n;i++) { if(!Vis[i]) { if(minn>Dis[i]) {Minn=Dis[i]; Next=i; } } } if(next<=N) solve (next);}intMain () {intLen; intnum; intTTT; scanf ("%d",&N); GetChar (); for(intI=1; i<=n;i++) { for(intj=1; j<=n;j++) {Pho[i][j]=inf; } Pho[i][i]=0; Dis[i]=inf; } for(intI=2; i<=n;i++) {gets (tmp[i]); } for(intI=2; i<=n;i++) {num=0; Len=strlen (Tmp[i]); Tmp[i][len]= +; TTT=0; for(intj=0; j<=len;j++) { if(tmp[i][j]== +) {num++; Pho[num][i]=pho[i][num]=TTT; TTT=0; } Else if(tmp[i][j]=='x') {TTT=inf; } Else{TTT*=Ten; TTT+=tmp[i][j]- -; } }} dis[1]=0; Solve (1); intmaxx=-1; for(intI=1; i<=n;i++) { if(maxx<Dis[i]) Maxx=Dis[i]; } printf ("%d\n", Maxx);}
POJ 1502 Water Dij