poj 1797 Heavy Transportation
来源:互联网 发布:钢琴入门自学软件 编辑:程序博客网 时间:2024/06/15 00:15
Heavy Transportation
Time Limit: 3000MS Memory Limit: 30000KTotal Submissions: 20261 Accepted: 5384
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.
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
13 31 2 31 3 42 3 5
Sample Output
Scenario #1:4
思路:dijkstra()的变形可以用Dijkstra变形一下,在松弛时要改变一下松弛的条件;
另外d数组中存储的不是每个点到1的最短距离,而是能够通过的最大载重;
#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>#include <stack>#include <queue>#include <set>#include <vector>using namespace std;#define maxn 1005#define INF 10000000int point[maxn][maxn];int d[maxn],flag[maxn];int n,m;void dijkstra(int v1){int i,j,k,v;for(i=0;i<=n;i++){flag[i]=0;d[i]=point[v1][i];}for(i=1;i<=n;i++){ int f=-1;for(j=1;j<=n;j++){if(!flag[j]&&d[j]>f){f=d[j];v=j;}}flag[v]=1;for(k=1;k<=n;k++){ if(!flag[k]&&d[k]<min(d[v],point[v][k])){ //条件 d[k]=min(d[v],point[v][k]); } }}} int main(){int t;int kase=1;int a,b,c;scanf("%d",&t);while(t--){scanf("%d %d",&n,&m);for(int i=0;i<=n;i++){for(int j=0;j<=n;j++){point[i][j]=0;}}for(int i=1;i<=m;i++){scanf("%d%d%d",&a,&b,&c);point[a][b]=point[b][a]=c; }dijkstra(1);printf("Scenario #%d:\n",kase++); printf("%d\n\n",d[n]);}return 0;}
0 0
- POJ 1797 Heavy Transportation
- POJ 1797 Heavy Transportation
- poj 1797Heavy Transportation
- poj 1797 Heavy Transportation
- POJ 1797 Heavy Transportation
- poj 1797 Heavy Transportation
- POJ 1797 Heavy Transportation
- POJ 1797 Heavy Transportation
- poj 1797 Heavy Transportation
- Poj 1797 Heavy Transportation
- poj 1797 Heavy Transportation
- poj 1797 Heavy Transportation
- POJ-1797-Heavy Transportation
- POJ 1797 Heavy Transportation
- poj 1797 Heavy Transportation
- poj 1797 Heavy Transportation
- POJ 1797 Heavy Transportation
- POJ 1797 Heavy Transportation
- 游戏源码2048
- 程序员面试问题(七)
- hdu 2079 选课时间(母函数)
- iOS 动画分类浅析
- hdoj 1863 畅通工程 【最小生成树】+【kruskal】
- poj 1797 Heavy Transportation
- CodeForces 370A Rook, Bishop and King(车,象,王到目的地的最小步数)
- EditText功能总结(2)
- Memory Management Policy
- hdu1828 Picture(线段树+离散化+扫描线)两种方法
- (三分法)Light Bulb
- Mac OSX 增删磁盘分区
- 【hdu4941】hash解决大行列交换问题~
- bnuoj 36905 Nested Segments