POJ 1797 Heavy Transportation SPFA Deformation

Source: Internet
Author: User

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

Heavy Transportation
Time Limit: 3000MS Memory Limit: 30000K
Total Submissions: 24576 Accepted: 6510

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

Source

TUD Programming Contest 2004, DARMSTADT, Germany test instructions

The limit size for a path is defined as the shortest edge on the path. I'm going to give you an no-go graph, asking you what the maximum limit is for all paths from 1 to N.

Exercises

Define Dp[i] represents the maximum limit size when walking from 1 to I. Then just like SPFA, each time from the queue to take out the slack, if the slack is successful, then the team.

Code
#include <iostream>#include<queue>#include<cstring>#include<algorithm>#include<vector>#include<cstdio>#defineINF 1000006#defineMax_n 1003using namespacestd;intD[max_n];intT;structNode { Public:    intu, c; Node (intUuintcc): U (UU), C (cc) {} node () {}};structEdge { Public:    intto, cost; Edge (intTintc): to (t), cost (c) {} edge () {}};queue<node>Que;vector<edge>G[max_n];voidSPFA (ints) {Que.push (node (s, INF)); D[s]=INF;  while(Que.size ()) {node now=Que.front ();        Que.pop (); if(now.c! = d[now.u])Continue; intU =now.u;  for(inti =0; I < g[u].size (); i++) {            intv =g[u][i].to; intt =min (d[u], g[u][i].cost); if(T >D[v]) {D[v]=T;            Que.push (Node (v, t)); }        }    }}intn,m;intMain () {scanf ("%d", &T); intCAS =0;  while(t--) {scanf ("%d%d", &n, &m);  for(inti =0; I <= N; i++) g[i].clear ();  while(Que.size ()) Que.pop (); memset (d,0,sizeof(d));  for(inti =0; I < m; i++) {            intu, V, c; scanf ("%d%d%d", &u, &v, &c);            G[u].push_back (Edge (V, c));        G[v].push_back (Edge (U, c)); } SPFA (1); printf ("Scenario #%d:\n%d\n\n", ++CAs, d[n]); }    return 0;}

POJ 1797 Heavy Transportation SPFA Deformation

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.