MPI Maelstrom POJ 1502

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.