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. Date 工具类(包含常用的一些时间方法)

    package com.fh.util; import java.sql.Timestamp; import java.text.DateFormat; import java.text.ParseE ...

  2. centos下testlink的部署(基于xampp)

    1. sudu -i 切换root用户      cd /opt切换到opt目录下(在linux下默认的下载文件目录在opt下) 执行命令下载xampp:      https://sourcefor ...

  3. APP功能性测试-1

    疑难点 根据软件说明()或用户需求()验证App的各个功能实现 根据需求,提炼App的用户使用场景,验证功能 根据测试指标,验证功能 根据被测试功能点的特性采用特定的方法进行测试(场景,边界值,,,) ...

  4. Android softkeyboard 和 其他界面关系 softInputMode

    转 : http://blog.csdn.net/xww810319/article/details/17397429 and http://blog.csdn.net/harryweasley/ar ...

  5. leetcode-组合总数IV(动态规划)

    377. 组合总和 Ⅳ 给定一个由正整数组成且不存在重复数字的数组,找出和为给定目标正整数的组合的个数. 示例: nums = [1, 2, 3] target = 4   所有可能的组合为: (1, ...

  6. 245. Subtree【LintCode java】

    Description You have two very large binary trees: T1, with millions of nodes, and T2, with hundreds ...

  7. 【转】UTF8字符串转换为汉字 c#,转自游戏开发主席

    using System; /// <summary> /// UTF8字符串转换为汉字用的类 /// 转换如"\\u8d35"之类的字符串为对应的汉字 /// < ...

  8. 4.安装hive

      下载安装包并解压安装元数据库配置hive添加hvie环境变量修改hive-env.sh修改hive配置文件初始化metastore使用hive cli配置hivemestore配置hiveserv ...

  9. Sail

    DescriptionThe polar bears are going fishing. They plan to sail from (sx,?sy) to (ex,?ey). However, ...

  10. javaIO--字符流

    java提供字符流对自否刘式文件进行数据读写操作.字符输入流类是Reader及其子类,输出流是Writer及其子类. 另外,上一篇javaIO写的是字节流,字节流方式也可以对以字符为基本类型的流式文件 ...