POJ.1797 Heavy Transportation (Dijkstra变形)
POJ.1797 Heavy Transportation (Dijkstra变形)
题意分析
- 给出n个点,m条边的城市网络,其中 x y d 代表由x到y(或由y到x)的公路所能承受的最大重量为d,求从1到n的所有通路中,所能经过的的最大重量的车为多少。
2.
代码总览
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <cmath>
#define nmax 1005
#define inf 1e8+7
using namespace std;
int t,n,m;
int mp[nmax][nmax];
int shortpath[nmax];
bool visit[nmax];
void dij(int s)
{
int cur = s;
memset(visit,0,sizeof(visit));
for(int i = 1;i<=n;++i){shortpath[i] = mp[cur][i];}
shortpath[cur] = 0;
visit[cur] = true;
for(int i = 1;i<=n-1 ;++i){
int minL = 0;
for(int j = 1;j<=n;++j){
if(!visit[j] && shortpath[j] != 0 && shortpath[j] >minL){
minL = shortpath[j];
cur = j;
}
}
visit[cur] = true;
for(int j = 1;j<=n;++j){
if(!visit[j]){
shortpath[j] = max(min(mp[cur][j],shortpath[cur]),shortpath[j]);
}
}
}
}
void init()
{
scanf("%d %d",&n,&m);
for(int i = 1;i<=n;++i)
for(int j = 1;j<=n;++j)
mp[i][j] = 0;
for(int i = 1;i<=m;++i){
int sta,end,dis;
scanf("%d %d %d",&sta,&end,&dis);
mp[sta][end] = mp[end][sta] = dis;
}
}
int main()
{
//freopen("in.txt","r",stdin);
int kase = 1;
scanf("%d",&t);
for(int i = 1;i<=t;++i){
init();
dij(1);
printf("Scenario #%d:\n",kase++);
printf("%d\n\n",shortpath[n]);
}
return 0;
}
POJ.1797 Heavy Transportation (Dijkstra变形)的更多相关文章
- POJ 1797 Heavy Transportation SPFA变形
原题链接:http://poj.org/problem?id=1797 Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K T ...
- POJ 1797 Heavy Transportation (Dijkstra)
题目链接:POJ 1797 Description Background Hugo Heavy is happy. After the breakdown of the Cargolifter pro ...
- POJ 1797 Heavy Transportation / SCU 1819 Heavy Transportation (图论,最短路径)
POJ 1797 Heavy Transportation / SCU 1819 Heavy Transportation (图论,最短路径) Description Background Hugo ...
- poj 1797 Heavy Transportation(最大生成树)
poj 1797 Heavy Transportation Description Background Hugo Heavy is happy. After the breakdown of the ...
- POJ 1797 Heavy Transportation
题目链接:http://poj.org/problem?id=1797 Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K T ...
- POJ 1797 Heavy Transportation (Dijkstra变形)
F - Heavy Transportation Time Limit:3000MS Memory Limit:30000KB 64bit IO Format:%I64d & ...
- POJ 1797 ——Heavy Transportation——————【最短路、Dijkstra、最短边最大化】
Heavy Transportation Time Limit:3000MS Memory Limit:30000KB 64bit IO Format:%I64d & %I64 ...
- POJ 1797 Heavy Transportation(最大生成树/最短路变形)
传送门 Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 31882 Accept ...
- POJ 1797 Heavy Transportation (dijkstra 最小边最大)
Heavy Transportation 题目链接: http://acm.hust.edu.cn/vjudge/contest/66569#problem/A Description Backgro ...
随机推荐
- 吴裕雄 python 机器学习——层次聚类AgglomerativeClustering模型
import numpy as np import matplotlib.pyplot as plt from sklearn import cluster from sklearn.metrics ...
- mysql数据库基本操作命令
1.登录命令 mysql -u root -p "password" 2.列出所有数据库 show databases; 3.使用数据库 use db_name 4.列出数据库中所 ...
- 180608-Git工具之Stash
git stash 暂存 背景: 实际开发过程中,经常可能遇到的一个问题,当你在dev分支上正开发得happy的时候:突然来了个线上bug,得赶紧从release分支上切一个bugfix分支来解决线上 ...
- MySQL☞upper函数
upper(列名/字符串):把小写字母改为大写字母 格式: select upper(列名/字符串) from 表名 如下图:
- Linux命令应用大词典-第31章 设备管理
31.1 udevadm info:查询udev数据库中的设备信息 31.2 mkdnod:创建块设备和字符设备文件 31.3 MAKEDEV:创建/dev中的设备 31.4 lsblk:列出块设备信 ...
- python数据分析基础——pandas Tutorial
参考pandas官方文档: http://pandas.pydata.org/pandas-docs/stable/10min.html#min 1.pandas中的数据类型 Series 带有索引标 ...
- 技本功丨知否知否,Redux源码竟如此意味深长(下集)
上集回顾 Redux是如何使用的?首先再来回顾一下这个使用demo(谁让这段代码完整地展示了redux的使用) 如果有小伙伴对这段代码不是很理解的话,建议先去学习Redux的使用再来看这篇源码,这样更 ...
- Simple Pipelined Function
SELECT * FROM TABLE(PKG_TEST.FN_DIC_DB_TAB) CREATE OR REPLACE PACKAGE PKG_TEST IS TYPE OBJ_DICDB_R ...
- [leetcode-783-Minimum Distance Between BST Nodes]
Given a Binary Search Tree (BST) with the root node root, return the minimum difference between the ...
- 最全NB-IoT/eMTC物联网解决方案名录汇总
NB-IoT/eMTC等蜂窝物联网技术的成熟和商用,占据低功耗广域网络(LPWAN)的主流地位,推动全球物联网新一轮发展热潮,越来越多的行业开始采用物联网方案来解决解决实际问题.实现落地应用,越来越多 ...