POJ-1797 Heavy Transportation (Shortest way)

Source: Internet
Author: User

Title Link: http://poj.org/problem?id=1797

Description

Background
Hugo Heavy is happy. After the breakdown of the Cargolifter project he can now expand business. But he needs a clever mans tells him whether there really is a-a-a-from-the-place his customer have build his giant stee L Crane to the place where it's needed on which all streets can carry the weight.
Fortunately he already have a plan of the city with all streets and bridges and all the allowed weights. Unfortunately he have no idea how to find the the the maximum weight capacity in order to tell him customer how heavy the crane May become. But you surely know.

Problem
You is given the plan of the city, described by the streets (with weight limits) between the crossings, which is numbere D from 1 to N. Your task is to find the maximum weight, can be transported from crossing 1 (Hugo's place) to crossing N (the customer ' s place). You are assume that there are at least one path. All streets can is travelled in both directions.

Input

The first line contains the number of scenarios (city plans). For each city the number N of the street crossings (1 <= n <=) and number M of streets is 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'll is at the most one street between each pair of crossings.

Output

The output for every scenario begins with a line containing "scenario #i:", where I am the number of the scenario starting at 1. Then print a, 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

Main topic: one has to ship from Route 1th to Route N, but each road has a load limit, asking the person to deliver multiple shipments.
Problem Solving Ideas: The shortest way to change the judging conditions to the weight of each road can be

1#include <iostream>2#include <cstring>3#include <algorithm>4#include <cmath>5#include <iomanip>6#include <map>7 8 using namespacestd;9 Ten intstreet[1005][1005], dis[1005]; One BOOLflag[1005]; A  - intMain () { -Ios::sync_with_stdio (false ); the  -     intT, N, m, x, y, temp; -CIN >>T; -      for(intt =1; T <= t; t++ ){ +CIN >> N >>m; -memset (Street,-1,sizeof(street)); +memset (Flag,true,sizeof(flag)); A          for(inti =0; I < m; i++ ){ atCin >> x >> y >>temp; -Street[x][y] = street[y][x] =temp; -         } -          for(inti =2; I <= N; i++ ){ -Dis[i] = street[1][i]; -         } in  -          for(intK =1; K < n; k++ ){ to             intMaxx =-1, Maxi =1; +              for(inti =2; I <= N; i++ ){ -                 if(Flag[i] && dis[i] >Maxx) { theMaxx =Dis[i]; *Maxi =i; $                 }Panax Notoginseng             } -  theFlag[maxi] =false; +  A              for(inti =2; I <= N; i++ ){ the                 if(Flag[i] && Dis[i] <min (Dis[maxi], street[maxi][i])) { +Dis[i] =min (Dis[maxi], street[maxi][i]); -                 } $             } $         } -  -cout <<"Scenario #"<< T <<":"<< Endl << dis[n] << Endl <<Endl; the     } - Wuyi     return 0; the}

POJ-1797 Heavy Transportation (Shortest way)

Related Article

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.