poj_1797 Heavy Transportation
来源:互联网 发布:linux开启smb服务 编辑:程序博客网 时间:2024/06/07 03:03
Heavy Transportation
Time Limit: 3000MS
Memory Limit: 30000K
Total Submissions: 15487
Accepted: 4026
题目链接http://poj.org/problem?id=1797
Description
Background
Hugo Heavy is happy. After the breakdown of the Cargolifter project he can nowexpand business. But he needs a clever man who tells him whether there reallyis a way from the place his customer has build his giant steel crane to theplace 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 andall the allowed weights.Unfortunately he has no idea how to find the themaximum weight capacity in order to tell his customer how heavy the crane maybecome. But you surely know.
Problem
You are given the plan of the city, described by the streets (with weightlimits) between the crossings, which are numbered from 1 to n. Your task is tofind 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 onepath. All streets can be travelled in both directions.
Input
The first line contains thenumber of scenarios (city plans). For each city the number n of streetcrossings (1 <= n <= 1000) and number m of streets are given on the firstline. The following m lines contain triples of integers specifying start andend crossing of the street and the maximum allowed weight, which is positive andnot larger than 1000000. There will be at most one street between each pair ofcrossings.
Output
The output for every scenariobegins with a line containing "Scenario #i:", where i is the numberof the scenario starting at 1. Then print a single line containing the maximumallowed weight that Hugo can transport to the customer. Terminate the outputfor 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
TUDProgramming Contest 2004, Darmstadt, Germany
题意:
求图中第一点到最后一点的每一条路径中最小值,然后这这些路径的最小值中在找出最大值,这个题目不好理解,所先理解成了求最短路径的最大边,后来有理解成了求最长路径的最短边,都理解错了,这个题目理解对了就不难做了,用Dijkstra算法求出第一点到最后一点的每一条路径的最小值放在数组中,在求数组中的最大值即可。
代码:
//求解从第一点到达最后一点的最小生成树的最大值#include <iostream>#include<cstdio>#include<cstring>#define MAX 12#define VALUE 0x3f3f3f3fusing namespace std;int n,m;//n个节点,m条边int g[MAX][MAX];int used[MAX];int d[MAX];int minValue(int a,int b){if(a>b)return b;return a;}int Dijkstra(){ int i;int pre=1;memset(used,0,sizeof(used));memset(d,0,sizeof(d));//第一点到最后一点的距离都置为0used[1]=true;d[1]=VALUE;while(true){for(i=1;i<=n;i++){if(!used[i] && minValue(d[pre],g[pre][i])>d[i])d[i]=minValue(d[pre],g[pre][i]);}int a=-1,b=-1;for(i=1;i<=n;i++){//遍历每一个点,如果该点没被访问过,并且从第一点到第i点的距离大于最大距离,记录该点编号iif(!used[i] && d[i]>a){a=d[i];b=i;}}if(b==-1)break;used[b]=true;pre=b;} return d[n];}int main(){ int ts; int i,j; int start,end,weight; scanf("%d",&ts); for(j=1;j<=ts;j++) { scanf("%d%d",&n,&m); memset(g,0,sizeof(g)); for(i=0;i<m;i++) { scanf("%d%d%d",&start,&end,&weight); g[start][end]=weight; g[end][start]=weight; } printf("Scenario #%d:\n",j); printf("%d\n\n",Dijkstra()); } return 0;}
- poj_1797 Heavy Transportation
- Heavy Transportation
- Heavy Transportation
- Heavy Transportation
- Heavy Transportation
- Heavy Transportation
- Heavy Transportation
- POJ 1797 Heavy Transportation
- POJ 1797 Heavy Transportation
- poj 1797Heavy Transportation
- poj 1797 Heavy Transportation
- POJ 1797 Heavy Transportation
- Heavy Transportation (POJ1797)
- poj 1797 Heavy Transportation
- poj1797 - Heavy Transportation
- POJ 1797 Heavy Transportation
- POJ 1797 Heavy Transportation
- poj 1797 Heavy Transportation
- [已删除]
- 使用NSFileManager枚举目录种的内容(遍历目录)
- poj_1125 Stockbroker Grapevine
- 使用dom4j:读取spring配置文件,实例化bean对象并注入依赖对象
- MFC中动态创建多个按钮并实现其消息响应
- poj_1797 Heavy Transportation
- delphiIDE调试使用小结
- Discuz 。net版下载地址:
- FileZilla Server搭建
- C语言的那些小秘密——字节对齐
- 输入外挂
- 工作中需要注意的15个问题。
- uva 10098 - Generating Fast
- poj_2513 Colored Sticks