#include <stdio.h>#include<string.h>#include<algorithm>using namespacestd;Const intMAXN = +;Const intINF =99999999;intMAP[MAXN][MAXN],N,M,DIS[MAXN][MAXN];intMaxintXinty) { returnX>y?x:y;}intFloyd () {inti,j,k; for(k=1; k<=n;k++) { for(i=1; i<=n;i++) { for(j=1; j<=n;j++) { if(dis[i][j]>dis[i][k]+Dis[k][j]) dis[i][j]=dis[i][k]+Dis[k][j]; } } } returndis[1][n];}intDelintu) { inti,j; for(i=1; i<=n;i++) { for(j=1; j<=n;j++) { if(I==J) dis[i][j]=INF; if(i==u| | j==u) dis[i][j]=INF; Else if(map[i][j]==0) Dis[i][j]=INF; Elsedis[i][j]=Map[i][j]; } } returnFloyd ();}intMain () {inti,j; while(SCANF ("%d%d", &n,&m)! =EOF) { if(!n&&!m) Break; memset (Map,0,sizeof(map)); for(i=0; i<m;i++) { intx, Y, Z scanf ("%d%d%d",&x,&y,&z); if(map[x][y]==0|| Map[x][y]>z) map[x][y]=map[y][x]=Z; } intFlag=del (0); if(flag>=INF) {printf ("inf\n"); Continue; } //printf ("%d\n", flag); intans=0; for(i=2; i<n;i++) { inttemp=del (i); Ans=Max (ans,temp); } if(ans>=INF) printf ("inf\n"); Elseprintf ("%d\n", ans); } }
HDU5137 Enumeration Delete Point