Poj 1797 Heavy Transportation (transient deformation)

Source: Internet
Author: User
Heavy Transportation
Time limit:3000 Ms   Memory limit:30000 K
Total submissions:20364   Accepted:5401

Description

Background
Hugo heavy is happy. after the breakdown of the cargolifter project he can now expand business. but he needs a clever man who tells him whether there really is a way from the place his customer has build his giant steel crane to the place where it is needed on which all streets can carry weight.
Fortunately he already has a plan of the city with all streets and bridges and all the allowed weights. unfortunately he has no idea how to find the maximum weight capacity in order to tell his customer how heavy the crane may become. but you surely know.

Problem
You are given the plan of the city, described by the streets (with weight limits) between the crossings, which are numbered from 1 to n. your task is to find the maximum weight that can be transported from crossing 1 (Hugo's place) to crossing N (the customer's place ). you may assume that there is at least one path. all streets can be traveled in both directions ctions.

Input

The first line contains the number of scenarios (city plans ). for each city the number n of street crossings (1 <= n <= 1000) and number M of streets are given on the first line. the following M lines contain triples of integers specifying start and end crossing of the street and the maximum allowed weight, which is positive and not larger than 1000000. there will be at most one street between each pair of crossings.

Output

The output for every scenario begins with a line ining "Scenario # I:", where I is the number of the scenario starting at 1. then print a single line containing the maximum allowed weight that Hugo can transport to the customer. terminate the output for the scenario with a blank line.

Sample Input

13 31 2 31 3 42 3 5

Sample output

Scenario #1:4

Source

Tud Programming Contest 2004, Darmstadt, Germany indicates that the road between two cities has a maximum bearing weight, and the maximum bearing weight from the start point to the end point. Because there are many routes from the start point to the end point, each path will have a "maximum" Bearing Weight (that is, the minimum carrying weight from the start point to the end point ), calculate the maximum load of all paths leading to the destination. The idea is similar to finding the shortest path. You can change the update conditions.
 1 #include<cstdio> 2 #include<cstring> 3 #include<stdlib.h> 4 #include<algorithm> 5 using namespace std; 6 const int MAXN=1000+10; 7 const int INF=0x3f3f3f3f; 8 int dis[MAXN],vis[MAXN],w[MAXN][MAXN]; 9 int n,m;10 void dijkstra()11 {12     memset(vis,0,sizeof(vis));13     for(int i=1;i<=n;i++)14         dis[i]=w[1][i];15     for(int i=1;i<=n;i++)16     {17         int x,temp=-1;18         for(int j=1;j<=n;j++)19         {20             if(!vis[j]&&dis[j]>temp)21             {22                 temp=dis[j];23                 x=j;24             }25         }26         vis[x]=1;27         for(int j=1;j<=n;j++)28             if(!vis[j]&&dis[j]<min(dis[x],w[x][j]))29                 dis[j]=min(dis[x],w[x][j]);30     }31 }32 int main()33 {34     //freopen("in.txt","r",stdin);35     int kase,cnt=0;36     scanf("%d",&kase);37     while(kase--)38     {39         for(int i=1;i<=n;i++)40             for(int j=1;j<=n;j++)41                 w[i][j]=0;42         scanf("%d %d",&n,&m);43         for(int i=1;i<=m;i++)44         {45             int star,en,val;46             scanf("%d %d %d",&star,&en,&val);47             w[star][en]=w[en][star]=val;48         }49         dijkstra();50         printf("Scenario #%d:\n",++cnt);51         printf("%d\n\n",dis[n]);52     }53     return 0;54 }
View code

 

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.