The shortest path, simple problem, Floyd implementation, in seeking a minimum road must be the maximum node number maxnum instead of the input n, otherwise is wrong.
#include <iostream> using namespace Std;int map[105][105]; No map void Init () {int max=1000000,i,j;for (i=1;i<=104;i++) for (j=1;j<=104;j++) if (i==j) Map[i][j]=0;else map[i][ J]=max;} void Floyd (int n) {for (int k=1;k<=n;k++) //k stands for Intermediate point for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) if (Map[i][k] +MAP[K][J]<MAP[I][J]) map[i][j]=map[i][k]+map[k][j];} int main () {int N,m,a,b,c,maxnum;while (cin>>n>>m && (n| | m) {Init (); maxnum=0; Maximum node number for (int i=0;i<m;i++) {cin>>a>>b>>c;map[a][b]=map[b][a]=c;maxnum=maxnum>a?maxnum: A;maxnum=maxnum>b?maxnum:b;} Floyd (Maxnum); Be sure to have the maximum node number instead of N. Cout<<map[1][n]<<endl;} return 0; }
HDU ACM 2544 Shortest Path