poj 1797 Heavy Transportation 最短路 dijkstra
来源:互联网 发布:jsp中引用js文件 编辑:程序博客网 时间:2024/05/21 08:04
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.
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.
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.
13 31 2 31 3 42 3 5
Scenario #1:4
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;typedef long long ll;const ll inf=0x3f3f3f3f;int vis[1020];ll d[1020];int f[1020];ll cost[1020][1020];int n,m;void dijkstra(){ int mini,k; for(int i=1;i<=n;i++) d[i]=cost[1][i]; for(int i=1;i<=n;i++) { mini=-1; for(int j=1;j<=n;j++) { if(!vis[j]&&d[j]>mini) { mini=d[j]; k=j; } } vis[k]=true; for(int i=1;i<=n;i++) { if(d[i]<min(d[k],cost[k][i])) d[i]=min(d[k],cost[k][i]); } }}int main(){ int t,icase=0; int x,y,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++) { cost[i][j]=0; } vis[i]=false; } for(int i=0;i<m;i++) { scanf("%d%d%d",&x,&y,&c); if(cost[x][y]<=c) { cost[x][y]=c; cost[y][x]=c; } } dijkstra(); printf("Scenario #%d:\n",++icase); printf("%lld\n\n",d[n]); } return 0;}
阅读全文
0 0
- poj 1797 Heavy Transportation 最短路 dijkstra
- poj-1797-Heavy Transportation [最短路][Dijkstra]
- poj 1797 Heavy Transportation 【最短路Dijkstra 变式】
- POJ 1797 Heavy Transportation【Dijkstra最短路变形】
- 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 2253 Frogger 最短路 dijkstra变形
- POJ-1797Heavy Transportation,最短路变形,用dijkstra稍加修改就可以了;
- POJ 1797 Heavy Transportation 【dijkstra】
- poj 1797 Heavy Transportation(dijkstra)
- POJ - 1797----Heavy Transportation(Dijkstra)
- POJ 1797 Heavy Transportation Dijstr最短路变形
- POJ 1797 Heavy Transportation(最小生成树或最短路)
- POJ 1797 Heavy Transportation 【最短路思维+最大承载】
- hive 教程
- 上传本地项目到github
- struts2模型驱动深入理解
- [NOIP2016提高组]D2T1:组合数问题
- Mat数据结构
- poj 1797 Heavy Transportation 最短路 dijkstra
- 白话经典算法系列之六 快速排序 快速搞定
- 【数论-莫比乌斯】hdu 6053 TrickGCD
- 异步任务
- 2017多校第4场 HDU 6071 Lazy Running 同余最短路
- 关于使用markdown的一点心得
- hdu3938(离线并查集)
- 三分-HDU3714
- 小白、教你学C++(8)异常处理结构层次