POJ 1797Heavy Transportation(dijkstral变形)
来源:互联网 发布:惠普扫描仪安装软件 编辑:程序博客网 时间:2024/06/15 23:49
题目:
- 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
1
3 3
1 2 3
1 3 4
2 3 5
Sample Output
Scenario #1:
4
题意是求:求到n点的所有路径中最小权值的最大值。
代码如下:
#include<iostream>#include<stdio.h>#include<string.h>#include<math.h>#include<vector>#include<queue>#include<stdlib.h>#include<algorithm>using namespace std;const int maxn=1100;const int INF=0x3f3f3f3f;int dis[maxn][maxn],len[maxn];bool vis[maxn];void Dijkstra(int n){ for(int i=1; i<=n; i++) { len[i]=0; vis[i]=false; } for(int i=1; i<=n; i++) len[i]=dis[1][i]; for(int j=0; j<n; j++) { int k=-1; int Min=0; for(int i=1; i<=n; i++) { if(!vis[i]&&len[i]>Min) { Min=len[i]; k=i; } } vis[k]=true; for(int i=1; i<=n; i++) if(!vis[i]&&min(len[k],dis[k][i])>len[i]) { if(len[k]!=0) len[i]=min(len[k],dis[k][i]); else if(dis[k][i]>len[i]) len[i]=dis[k][i]; } }}int main(){ int T,flag,n,m,a,b,c; flag=0; scanf("%d",&T); while(flag<T) { flag++; memset(dis,0,sizeof(dis)); scanf("%d%d",&n,&m); for(int i=1; i<=m; i++) { scanf("%d%d%d",&a,&b,&c); dis[a][b]=c; dis[b][a]=c; } Dijkstra(n); printf("Scenario #%d:\n",flag); printf("%d\n\n",len[n]); } return 0;}
- POJ 1797Heavy Transportation(dijkstral变形)
- POJ 1797 Heavy Transportation(dijkstra变形)
- POJ-1797(dijstra变形)(Heavy Transportation)
- POJ 1797 Heavy Transportation(单源最短路径变形)
- poj 1797 Heavy Transportation (最短路变形)
- 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 (Dijkstra变形)
- Poj 1797 Heavy Transportation ( 最短路变形
- Heavy Transportation(POJ-1797)
- POJ 1797 Heavy Transportation(Dijkstra变形) 解题报告
- POJ 1797 Heavy Transportation Dijstr最短路变形
- 7_4_O题 Heavy Transportation 题解[POJ 1797](Dijkstra变形)
- POJ 1797 Heavy Transportation【Dijkstra最短路变形】
- POJ 1797Heavy Transportation Dijkstra变形与优化
- EditText内容的动态监听方法
- 火狐浏览器httpRequest插件
- 区块链3.0(三): 去中心化的域名系统Namecoin
- CodeForces 731A Night at the Museum
- ACboy needs your help again!
- POJ 1797Heavy Transportation(dijkstral变形)
- IView中on-change属性的使用
- js复制到剪贴板
- 关闭笔记本电脑触控板的方法
- Ubuntu用户和组以及权限
- DB2 with实现递归
- docker 中不能用vim编辑文件
- 用Python学《微积分B》(不定积分的概念)
- 打印二叉树边界节点