pku 1797 Heavy Transportation(最短路径)
2013-06-24 11:57
162 查看
Heavy Transportation
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
Sample Output
Source
TUD Programming Contest 2004, Darmstadt, Germany
题意:每条路均有一个负载,求由点1到点n的可以带的最大负载
题解:dij算法改一下条件就可以了
Time Limit: 3000MS | Memory Limit: 30000K | |
Total Submissions: 17337 | Accepted: 4556 |
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到点n的可以带的最大负载
题解:dij算法改一下条件就可以了
#include <stdio.h> #include<string.h> #define INF 0xffffff int l[1005],mark[1005],d[1005][1005]; int n,m,x,y,len; int MIN(int a,int b) { if(a>b) return b; else return a; } int MAX(int a,int b) { if(a>b) return a; else return b; } int dij() { int flag=1,i,j,m; for(i=0;i<n&&flag;i++) { for(flag=m=0,j=1;j<=n;j++) { if(!mark[j]&&l[j]>m) m=l[x=j],flag=1; } for(mark[x]=1,j=1;j<=n;j++) l[j]=MAX(l[j],MIN(l[x],d[x][j])); } return l ; } int main() { int t,T,i; scanf("%d",&T); for(t=1;t<=T;t++) { scanf("%d%d",&n,&m); memset(d,-1,sizeof(d)); for(i=0;i<m;i++) { scanf("%d%d%d",&x,&y,&len); d[x][y]=d[y][x]=len; } for(l[1]=INF,i=2;i<=n;i++) l[i]=-INF; memset(mark,0,sizeof(mark)); printf("Scenario #%d:\n%d\n",t,dij()); if(t!=T) printf("\n"); } return 0; }
相关文章推荐
- pku 1511 Invitation Cards(最短路径)
- pku 1847(最短路径,floyd)
- pku openjudge 我爱北大 floyd算法求最短路径
- PKU1511(Invitation Cards)最短路径-邻接表+SPFA算法
- pku 1511(最短路径,spfa静态邻接表)
- 完全最短路径问题Floyd算法 pku 1125 Stockbroker Grapevine
- POJ 1797 Heavy Transportation / SCU 1819 Heavy Transportation (图论,最短路径)
- poj 1797 dijkstra最短路径
- poj 1797 Heavy Transportation(最短路径Dijkdtra)
- pku 2394(最短路径,dijkastra)
- POJ 1797 Heavy Transportation(单源最短路径变形)
- PKU3013(Big Christmas Tree)-最短路径-SPFA
- PKU 1847 最短路径 djistrla
- nyoj_7,xyoj 1797街区最短路径问题
- PKU1125 最短路径 Floyd-Warshall算法
- PKU1062(昂贵的聘礼)单源点最短路径-Dijkstra算法
- Pku acm 1062 昂贵的聘礼 数据结构题目解题报告(七)—单源最短路径:Dijkstra算法
- pku 1151 Invitation Cards(单源最短路径 SPFA)
- pku 3259(最短路径,spfa)
- PKU 1062 单源最短路径