http://poj.org/problem?id=1502
Test instructions: This is a lower triangle, the upper triangle is consistent with the triangle graph, (if the complete matrix, the equivalent of map[i][j] distance is the corresponding value) This problem is the same. The difference is that if the ' x ' letter is displayed, the description map[i][j] is positive infinity, and the two points do not pass. Now the problem is: Ask 1 to 2, 1 to 3, .... 1 to n which is the shortest road.
****
English really is too slag, said to understand test instructions is not general difficult Ah, but understand test instructions after really good simple%>_<%.
Do not test my English again, I honestly say that level four has not%>_<% ...
#include <stdio.h>#include<string.h>#include<math.h>#include<queue>#include<algorithm>using namespacestd;#defineMAXN 110#defineOO 0x3f3f3f3fintMAPS[MAXN][MAXN], V[MAXN], DIST[MAXN];intN;voidInit () { for(intI=1; i<=n; i++) { for(intj=1; j<=n; J + +) { if(i==j) Maps[i][j]=0; ElseMaps[i][j]= Maps[j][i] =Oo; } }}voidDij () {memset (V,0,sizeof(v)); memset (Dist,0,sizeof(Dist)); for(intI=1; i<=n; i++) Dist[i]= maps[1][i]; v[1] =1; for(intI=1; i<n; i++) { intindex, mins =Oo; for(intj=1; j<=n; J + +) { if(!v[j] && Dist[j] <mins) {Index=J; Mins=Dist[j]; }} V[index]=1; for(intj=1; j<=n; J + +) { if(Dist[j] > mins + maps[index][j] &&!V[j]) dist[j]= mins +Maps[index][j]; } } intAns =0; for(intI=1; i<=n; i++) ans=Max (ans, dist[i]); printf ("%d\n", ans);}intMain () {CharSTR[MAXN]; intnum; while(SCANF ("%d", &n)! =EOF) {Init (); for(intI=2; i<=n; i++) { for(intj=1; j<i; J + +) {scanf ("%s", str); if(str[0] !='x') {sscanf (str,"%d", &num); MAPS[I][J]= Maps[j][i] =min (maps[i][j], num); }}} dij (); } return 0;}View Code
MPI Maelstrom POJ 1502