POJ.1797 Heavy Transportation (Dijkstra变形)

题意分析

  1. 给出n个点,m条边的城市网络,其中 x y d 代表由x到y(或由y到x)的公路所能承受的最大重量为d,求从1到n的所有通路中,所能经过的的最大重量的车为多少。
  2. 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变形)的更多相关文章

  1. POJ 1797 Heavy Transportation SPFA变形

    原题链接:http://poj.org/problem?id=1797 Heavy Transportation Time Limit: 3000MS   Memory Limit: 30000K T ...

  2. POJ 1797 Heavy Transportation (Dijkstra)

    题目链接:POJ 1797 Description Background Hugo Heavy is happy. After the breakdown of the Cargolifter pro ...

  3. POJ 1797 Heavy Transportation / SCU 1819 Heavy Transportation (图论,最短路径)

    POJ 1797 Heavy Transportation / SCU 1819 Heavy Transportation (图论,最短路径) Description Background Hugo ...

  4. poj 1797 Heavy Transportation(最大生成树)

    poj 1797 Heavy Transportation Description Background Hugo Heavy is happy. After the breakdown of the ...

  5. POJ 1797 Heavy Transportation

    题目链接:http://poj.org/problem?id=1797 Heavy Transportation Time Limit: 3000MS   Memory Limit: 30000K T ...

  6. POJ 1797 Heavy Transportation (Dijkstra变形)

    F - Heavy Transportation Time Limit:3000MS     Memory Limit:30000KB     64bit IO Format:%I64d & ...

  7. POJ 1797 ——Heavy Transportation——————【最短路、Dijkstra、最短边最大化】

    Heavy Transportation Time Limit:3000MS     Memory Limit:30000KB     64bit IO Format:%I64d & %I64 ...

  8. POJ 1797 Heavy Transportation(最大生成树/最短路变形)

    传送门 Heavy Transportation Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 31882   Accept ...

  9. POJ 1797 Heavy Transportation (dijkstra 最小边最大)

    Heavy Transportation 题目链接: http://acm.hust.edu.cn/vjudge/contest/66569#problem/A Description Backgro ...

随机推荐

  1. * 197. Permutation Index【LintCode by java】

    Description Given a permutation which contains no repeated number, find its index in all the permuta ...

  2. docker容器学习笔记

    docker是通过内核虚拟化技术来提供容器的资源隔离与安全保障. docker组成: docker client.docker server.docker组件(镜像(image).容器(contain ...

  3. 吴恩达深度学习 反向传播(Back Propagation)公式推导技巧

    由于之前看的深度学习的知识都比较零散,补一下吴老师的课程希望能对这块有一个比较完整的认识.课程分为5个部分(粗体部分为已经看过的): 神经网络和深度学习 改善深层神经网络:超参数调试.正则化以及优化 ...

  4. 六: Image Viewer 离线镜像查看器

    参考:http://hadoop.apache.org/docs/r2.6.3/hadoop-project-dist/hadoop-hdfs/HdfsImageViewer.html   离线镜像查 ...

  5. [leetcode-693-Binary Number with Alternating Bits]

    Given a positive integer, check whether it has alternating bits: namely, if two adjacent bits will a ...

  6. nodejs在linux环境下安装更新方式

    #检查是否已经安装 rpm -qa | grep python #查版本 python #最好是重新安装 Python推荐版本( >= v2.5.0 & < 3.0.0 ),否则影 ...

  7. Linux 应用笔记

    Linux 应用笔记 Linux 应用笔记 小书匠 Raspberry Pi 常用命令 CentOs Raspberry Ubuntu python 实用教程 Vim 权限问题 内存分配 shell ...

  8. 《剑指Offer》题四十一~题五十

    四十一.数据流中的中位数 题目:如何得到一个数据流中的中位数?如果从数据流中读出奇数个数值,那么中位数就是所有数值排序之后位于中间的数值.如果从数据流中读出偶数个数值,那么中位数就是所有数值排序之后中 ...

  9. JavaScript:理解事件、事件处理函数、钩子函数、回调函数

    详情请点击 http://www.jianshu.com/p/a0c580ed3432

  10. mysql学习之数据备份与恢复

    该文使用mysql5.5 centos6.5 64位(本人使用rpm安装mysql,数据库的安装目录默认) 一.数据备份注意事项 读锁问题:数据库(或者某个表)一旦进行读锁操作则影响数据库的写操作所以 ...