HDU ACM 2544 Shortest Path

Source: Internet
Author: User

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

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.