Test instructions: From the 2~n-1 these points arbitrarily remove a point, so that the shortest path from 1 to n maximum, if arbitrarily remove a point 1~n no path output INF.
Sample Input
4 5
1 2 3
1 3 7
1 4 50
2 3 4
3 4 2
3 2
1 2 30
2 3 10
0 0
Sample Output
50
Inf
1# include <iostream>2# include <cstdio>3# include <cstring>4# include <algorithm>5# include <string>6# include <map>7# include <cmath>8# include <queue>9# include <list>Ten# define LLLong Long One using namespacestd; A - Const intmaxn= -; - Const intinf=0x3f3f3f3f; the intN, M; - BOOLVIS[MAXN]; - intCOST[MAXN][MAXN]; - intLOWCOST[MAXN]; + - voidDijkstra (intBeg) + { A for(intI=0; i<n;i++) at { -lowcost[i]=INF; - } -lowcost[beg]=0; - for(intj=0; j<n;j++) - { in intk=-1; - intmin=INF; to for(intI=0; i<n;i++) + if(!vis[i]&&lowcost[i]<Min) - { themin=Lowcost[i]; *k=i; $ }Panax Notoginseng if(k==-1) - Break ; thevis[k]=true; + for(intI=0; i<n;i++) A if(!vis[i]&&lowcost[k]+cost[k][i]<Lowcost[i]) the { +lowcost[i]=lowcost[k]+Cost[k][i]; - } $ } $ - } - the intMain () - {Wuyi //freopen ("In.txt", "R", stdin); the while(SCANF ("%d%d", &n, &m)! =EOF) - { Wu if(n = =0&& m = =0) - Break ; About $ intu, V, W; - intI, J; - intMAX =0 ; - for(i =0; I < n; i++) A for(j =0; J < N; J + +) + { the if(i = =j) -COST[I][J] =0 ; $ Else theCOST[I][J] =INF; the } the while(m--) the { -scanf"%d%d%d", &u, &v, &W); incost[u-1][v-1] =W; thecost[v-1][u-1] =W; the About } the the for(i =1; I <= N-2; i++) the { +memset (Vis,0,sizeof(Vis)); -Vis[i] =1 ; theDijkstra (0) ;Bayi if(lowcost[n-1] >MAX) theMAX = lowcost[n-1] ; the - } - the if(MAX = =INF) theprintf"inf\n") ; the Else theprintf"%d\n", MAX); - } the the return 0 ; the}
View Code
Hdu 5137 Remove a point to make the shortest way maximum (2014 Guangzhou regional game k)