Poj 1797 Heavy Transportation

Source: Internet
Author: User

This question is about selecting the maximum load path from 1 to n and finding the maximum load.

To obtain the maximum load, we need to find the minimum load that each route can carry.

You can use Dijkstra algorithm to find

Assume that the current maximum load before is d [x] And now the route W [x] [Y] is used to reach y.

We will compare and classify d [X] and W [x] [Y] To get d [Y].

 

#include<stdio.h>#include<string.h>#include<math.h>#include<iostream>#include<algorithm>#include<queue>#include<stack>#define mem(a,b) memset(a,b,sizeof(a))#define ll __int64#define MAXN 1000#define INF 0x7ffffff#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1using namespace std;int w[1200][1200];int d[1200];int v[1200];int main(){    int t,n,m,cas=1;    int i,j;    int a,b,c;    cin>>t;    while(t--)    {        printf("Scenario #%d:\n",cas++);        cin>>n>>m;        mem(w,0);        mem(v,0);        while(m--)        {            scanf("%d%d%d",&a,&b,&c);            w[a][b]=w[b][a]=c;        }        for(int i=1;i<=n;i++)                    d[i]=(i==1?INF:0);        for(i=1;i<=n;i++)        {            int x,maxx=0;            for(int y=1;y<=n;y++)                if(!v[y]&&d[y]>=maxx) maxx=d[x=y];            v[x]=1;            for(int y=1;y<=n;y++)            {                if(d[x]>=w[x][y]&&w[x][y]>d[y])                {                    d[y]=w[x][y];                }                else if(d[x]<w[x][y]&&d[x]>d[y])                {                    d[y]=d[x];                }            }        }        cout<<d[n]<<endl<<endl;    }    return 0;}

  

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.