Heavy Transportation(POJ - 1797 变形版 dijkstra)
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
//注意题上最后让输出2个换行
//#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<math.h>
#include<cstdio>
#include<sstream>
#include<numeric>//STL数值算法头文件
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<functional>//模板类头文件
using namespace std;
const int INF=1e9+7;
const int maxn=1100;
typedef long long ll;
int t,n,m;
int vis[maxn];
int par[maxn];
int tu[maxn][maxn];
int dijkstra()
{
int i,j,k;
memset(vis,0,sizeof(vis));
for(i=1; i<=n; i++)
par[i]=tu[1][i];
for(i=1; i<=n; i++)
{
int minn=-1;
for(j=1; j<=n; j++)
{
if(!vis[j]&&minn<par[j])
{
k=j;
minn=par[j];
}
}
vis[k]=1;
for(j=1; j<=n; j++)
{
par[j]=max(par[j],min(tu[k][j],par[k]));
// if(!vis[j]&&par[j]<min(tu[k][j],par[k]))
// {
// par[j]=min(tu[k][j],par[k]);
// }
}
}
return par[n];
}
int main()
{
int cot=1;
scanf("%d",&t);
while(t--)
{
int i,j,a,b,c;
scanf("%d %d",&n,&m);
memset(tu,0,sizeof(tu));
while(m--)
{
scanf("%d %d %d",&a,&b,&c);
tu[a][b]=tu[b][a]=c;
}
printf("Scenario #%d:\n",cot++);
printf("%d\n\n",dijkstra());
}
return 0;
}
Heavy Transportation(POJ - 1797 变形版 dijkstra)的更多相关文章
- Heavy Transportation POJ 1797 最短路变形
Heavy Transportation POJ 1797 最短路变形 题意 原题链接 题意大体就是说在一个地图上,有n个城市,编号从1 2 3 ... n,m条路,每条路都有相应的承重能力,然后让你 ...
- POJ 1797 Heavy Transportation 最短路变形(dijkstra算法)
题目:click here 题意: 有n个城市,m条道路,在每条道路上有一个承载量,现在要求从1到n城市最大承载量,而最大承载量就是从城市1到城市n所有通路上的最大承载量.分析: 其实这个求最大边可以 ...
- Heavy Transportation POJ - 1797
题意 给你n个点,1为起点,n为终点,要求所有1到n所有路径中每条路径上最小值的最最值. 思路 不想打最短路 跑一边最大生成树,再扫一遍1到n的路径,取最小值即可,类似Frogger POJ - 22 ...
- kuangbin专题专题四 Heavy Transportation POJ - 1797
题目链接:https://vjudge.net/problem/POJ-1797 思路:请参考我列出的另一个题目,和这个题目要求的值相反,另一个清楚后,这个写的解释就明白了. 另一个类似题目的博客:h ...
- POJ 1797 ——Heavy Transportation——————【最短路、Dijkstra、最短边最大化】
Heavy Transportation Time Limit:3000MS Memory Limit:30000KB 64bit IO Format:%I64d & %I64 ...
- POJ1797 Heavy Transportation —— 最短路变形
题目链接:http://poj.org/problem?id=1797 Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K T ...
- poj 1797 Heavy Transportation(Dijkstar变形)
http://poj.org/problem?id=1797 给定n个点,及m条边的最大负载,求顶点1到顶点n的最大载重量. 用Dijkstra算法解之,只是需要把“最短路”的定义稍微改变一下, A到 ...
- POJ1797 Heavy Transportation (堆优化的Dijkstra变形)
Background Hugo Heavy is happy. After the breakdown of the Cargolifter project he can now expand bus ...
- POJ.1797 Heavy Transportation (Dijkstra变形)
POJ.1797 Heavy Transportation (Dijkstra变形) 题意分析 给出n个点,m条边的城市网络,其中 x y d 代表由x到y(或由y到x)的公路所能承受的最大重量为d, ...
随机推荐
- 基于html5的动画库,非svg和canvas
基于html5的动画库,非svg和canvas https://greensock.com/docs/#/HTML5/GSAP/TweenLite/
- Fermat2018游记
day (-22) 2018年2月5日 Devin大佬给我发了一份Waterloo AIF的原件截图,发现里面居然直接问你的Fermat分数,那么这么重要的考试当然不能错过啊 若干天之后刚开学不久的一 ...
- React组件生命周期小结
React组件生命周期小结 下面所写的,只适合前端的React.(React也支持后端渲染,而且和前端有点小区别,不过我没用过.) 相关函数 简单地说,React Component通过其定义的几个函 ...
- Spring注解@Resource和@Autowired区别对比、spring扫描的默认bean的Id、程序获取spring容器对象
-------------------------注解扫面的bean的ID问题-------------------------- 0.前提需要明白注解扫描出来的bean的id默认是类名首字母小写,当 ...
- Linux 入门记录:九、Linux 文件系统挂载管理
一.挂载操作 磁盘或分区创建好文件系统后,需要挂载到一个目录才能够使用. Windows 或 Mac 系统会进行自动挂载,一旦创建好文件系统后会自动挂载到系统上,Windows 上称之为 C 盘.D ...
- Laravel 项目登录报错:The MAC is invalid.
在 Laravel 项目完成部署到服务器.数据库导入成功后 后台登录报错: 原因是 Laravel 的 APP_KEY 和 encrypt() 函数加密的问题.(encrypt() 是 Laravel ...
- python基础===【字符串】所有相关操作
#字符串的相关操作 #基本操作 #+ 字符串连接操作 str1 = '来是come走是go' str2 = '点头yes摇头no' result = str1 + str2 print(result) ...
- xshell+xming连接服务器虚拟机启动mininet网络
困于vnc连实验室的服务器虚拟机,一直出现页面不稳定的情况,然后本机虚拟机又带不起来,今天跟学弟交流,知道了ssh连接服务器的办法,心情好晴朗! xshell下载和安装,xshell使用 xshell ...
- Pylot网站Web服务器性能和负载压力测试-适用Windows可绘制图表
为了能够准确地评估网站服务器对网络流量的承受能力,我们一般会采取模拟网站用户访问,通过不断地增加并发数,延长访问时长,从而最终得出网站Web服务器的性能和负载能力.当然也可以通过Web压力测试,来完善 ...
- Network——物理层-练习题与解答
1. 无线电天线通常在其直径等于无线电波的波长的情况下工作效果最好.合理的天线直径的范围是从1厘米到5米.问所覆盖的频率范围是怎样的? 解答: λf = c , c=3x108 (m/s) 对于λ=1 ...