Heavy Transportation
Time Limit: 3000MS |
|
Memory Limit: 30000K |
Total Submissions: 29682 |
|
Accepted: 7919 |
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
Original title Link: http://poj.org/problem?id=1797
Test instructions: There are n cities, M roads, each road has a certain load-bearing, ask you to start from 1 to reach the maximum load capacity of n (the minimum value of all the bearing weight on the route).
Idea: Still the shortest-circuit problem, change the judging conditions can be.
Dijkstra Algorithm AC code:
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm>using namespace std;const int inf=0x3f3f3f3f;const int maxn=1005;int a[maxn][maxn];bool vis[maxn];int dis[maxn];int n;void Dij () {for (i NT i=1;i<=n;i++) {vis[i]=false; Dis[i]=a[1][i]; } vis[1]=true; dis[1]=0; for (int i=1;i<=n;i++) {int p; int maxx=0;//This question to find the largest for (int j=1;j<=n;j++) {//Key code if (!vis[j]&&dis[j]>m Axx) Maxx=dis[p=j]; } vis[p]=true; for (int j=1;j<=n;j++) {//Key code if (!vis[j]&&dis[j]<min (A[p][j],dis[p])) {dis[j]=min (a[p][j],dis[p]); }}}}int Main () {int T; int kase=0; cin>>t; while (t--) {int m; scanf ("%d%d", &n,&m); int x, y, Z; memset (A,0,sizeof (a));//Initialize for (int i=1;i<=m;i++) { scanf ("%d%d%d", &x,&y,&z); if (Z>a[x][y]) a[x][y]=a[y][x]=z; } dij (); printf ("Scenario #%d:\n", ++kase); printf ("%d\n\n", Dis[n]); } return 0;}
POJ 1797 Heavy Transportation "Dijkstra Shortest Path Distortion"