POJ 1797 Heavy Transportation (Dijkstra variant)

Source: Internet
Author: User

F-heavy TransportationTime limit:3000MS Memory Limit:30000KB 64bit IO Format:%i64d &%i6 4u Submit Status Practice POJ 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 Each road has a limited weight

The maximum number of goods that can be loaded from 1 to n
#include <stdio.h>#include<string.h>#include<iostream>#include<algorithm>using namespacestd;//const int INF=0X7FFFFFFF;Const intmaxn=1010;//#define TYPEC intConst intinf=0x3f3f3f3f;//prevent back overflow, this can't be too bigBOOLVIS[MAXN];intDIS[MAXN];intMAP[MAXN][MAXN];intN;voidDijkstra (intBeg) {     for(intI=1; i<=n; i++) {Dis[i]=Map[beg][i]; Vis[i]=false; } Dis[beg]=0;  for(intj=0; j<n; J + +)    {        intk=-1; intmin=-1;  for(intI=1; i<=n; i++)            if(!vis[i]&&dis[i]>Min) {Min=Dis[i]; K=i; }        if(k==-1)            Break; VIS[K]=true;  for(intI=1; i<=n; i++)            if(!vis[i]&&dis[i]<min (dis[k],map[i][k])) {Dis[i]=min (dis[k],map[i][k]); }    }}intMain () {intT; scanf ("%d",&t); intCnt=0;  while(t--) {CNT++; intm; memset (Vis,false,sizeof(VIS)); scanf ("%d%d",&n,&m); /*for (int i=1;i<=n;i++) {for (int j=i;j<=n;j++) {if (i==j) map[i][i]=0;           else Map[i][j]=map[j][i]=inf; }        }*/memset (Map,0,sizeof(map)); intu,v,w;  for(intI=1; i<=m;i++) {scanf ("%d%d%d",&u,&v,&W); MAP[U][V]=map[v][u]=W; } Dijkstra (1); printf ("Scenario #%d:\n", CNT); printf ("%d\n", Dis[n]); Puts (""); }    return 0;}

POJ 1797 Heavy Transportation (Dijkstra variant)

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.