POJ 1797 Heavy Transportation (最短路变形)

Heavy Transportation

Time Limit: 3000MS   Memory Limit: 30000K
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 the 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 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 travelled in both directions.

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 containing "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

1

3 3

1 2 3

1 3 4

2 3 5

Sample Output

Scenario #1:

4

Source

TUD Programming Contest 2004, Darmstadt, Germany
 
题目的意思就是说两个城市之间的道路有一个最大承载重量,求从起点通向终点的道路里面的最大承载重量。
因为起点到终点会有很多路,每一条路都会有一个“最大”承载重量(也就是这条从起点到终点的路上最小的承载重量),求所有通向终点的路中承载重量的最大是多少。
思路和求最短路差不多,改变更新条件就可以了
 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

 

你可能感兴趣的:(port)