POJ—1797(Heavy Transportation)

Heavy Transportation
Time Limit: 3000MS
Memory Limit: 30000K
Total Submissions: 39744
Accepted: 10443

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


题意分析:Hugo想要扩展他的公司,他有起重机要到目的地,到达目的地有很多条路径,但是,每一条路都有相应承重量,现在需要找出到达目的地的最大承重道路的承重质量。


解题分析:首先,每一条路径的承重量取决于承重量最小的那条道路(短板效应),所以就是找所有路径的最小值,然后选择最小值最大的路径,输出其最小值,这是最短路的变种,需要运用松弛操作,遍历所有路径,记录每条路径的最小值,同时选择同目的地路径最大值。


AC code

#include
#include
#include
using namespace std;
int map[1010][1010];
const int integer = 99999999;
int main(void){
	int a;
	int t=0;
	scanf("%d",&a);
	while(a--)
	{
		int b,c;
		int i,j;
		int d[1010];
		int v[1010];
		int site1,site2,dis;
		scanf("%d%d",&b,&c);
		memset(v,0,sizeof(v));
		//切记初始化,要不然会一直 Runtime Error ; 
		for(i=0;i<1001;i++)
		   for(j=0;j<1001;j++)
		        map[i][j] = 0 ;
		//转换为邻接矩阵 
		for(i=0;i



你可能感兴趣的:(图论,贪心)