本题思路:最短路变形,改变松弛方式即可,dist存的是源结点到当前结点的最长路的最小权值。

  参考代码:

 #include <cstdio>
#include <cstring>
#include <algorithm>
#define INF 0x3f3f3f3f
using namespace std; const int maxn = + ;
int n, m, k, Case = , G[maxn][maxn], dist[maxn];
bool vis[maxn]; int Dijkstra(int source, int aid) {
for(int i = ; i <= n; i ++)
dist[i] = (i == source ? INF : );
for(int i = ; i <= n; i ++) {
int minf = -;
for(int j = ; j <= n; j ++)
if(!vis[j] && minf < dist[j]) {
minf = dist[j];
k = j;
}
vis[k] = true;
if(minf == - ) break;
for(int j = ; j <= n; j ++)
if(!vis[j] && dist[j] < min(dist[k], G[k][j]))
dist[j] = min(dist[k], G[k][j]);
}
return dist[aid];
} int main () {
int t, x, y, w;
scanf("%d", &t);
while(t --) {
memset(vis, false, sizeof vis);
for(int i = ; i <= n; i ++) {
for(int j = ; j <= n; j ++)
G[i][j] = ;
}
scanf("%d %d", &n, &m);
for(int i = ; i <= m; i ++) {
scanf("%d %d %d", &x, &y, &w);
G[x][y] = G[y][x] = max(G[x][y], w);
}
printf("Scenario #%d:\n%d\n\n", ++Case, Dijkstra(, n));
}
return ;
}

POJ-1797.HeavyTransportation(最长路中的最小权值)的更多相关文章

  1. POJ 3790 最短路径问题(Dijkstra变形——最短路径双重最小权值)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3790 Problem Description 给你n个点,m条无向边,每条边都有长度d和花费p,给你 ...

  2. poj 2253 Frogger (最长路中的最短路)

    链接:poj 2253 题意:给出青蛙A,B和若干石头的坐标,现青蛙A想到青蛙B那,A可通过随意石头到达B, 问从A到B多条路径中的最长边中的最短距离 分析:这题是最短路的变形,曾经求的是路径总长的最 ...

  3. HihoCoder1576 子树中的最小权值( dfs序 +线段树 || 树剖)

    给定一棵N个节点的树,编号1~N.其中1号节点是根,并且第i个节点的权值是Vi. 针对这棵树,小Hi会询问小Ho一系列问题.每次小Hi会指定一个节点x,询问小Ho以x为根的子树中,最小的权值是多少.为 ...

  4. 【HIHOCODER 1576】 子树中的最小权值(线段树维护DFS序)

    描述 给定一棵N个节点的树,编号1~N.其中1号节点是根,并且第i个节点的权值是Vi. 针对这棵树,小Hi会询问小Ho一系列问题.每次小Hi会指定一个节点x,询问小Ho以x为根的子树中,最小的权值是多 ...

  5. POJ 1797 Heavy Transportation(Dijkstra变形——最长路径最小权值)

    题目链接: http://poj.org/problem?id=1797 Background Hugo Heavy is happy. After the breakdown of the Carg ...

  6. Frogger POJ - 2253(求两个石头之间”所有通路中最长边中“的最小边)

    题意 ​ 题目主要说的是,有两只青蛙,在两个石头上,他们之间也有一些石头,一只青蛙要想到达另一只青蛙所在地方,必须跳在石头上.题目中给出了两只青蛙的初始位置,以及剩余石头的位置,问一只青蛙到达另一只青 ...

  7. POJ 3565 Ants 【最小权值匹配应用】

    传送门:http://poj.org/problem?id=3565 Ants Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: ...

  8. POJ 2195 Going Home 【二分图最小权值匹配】

    传送门:http://poj.org/problem?id=2195 Going Home Time Limit: 1000MS   Memory Limit: 65536K Total Submis ...

  9. 【POJ 2400】 Supervisor, Supervisee(KM求最小权匹配)

    [POJ 2400] Supervisor, Supervisee(KM求最小权匹配) Supervisor, Supervisee Time Limit: 1000MS   Memory Limit ...

随机推荐

  1. 前端基础----CSS语法、CSS四种引入方式、CSS选择器、CSS属性操作

    一.CSS语法 CSS 规则由两个主要的部分构成:选择器,以及一条或多条声明. 例如: h1 {color:red; font-size:14px;} 二.CSS四种引入方式 1,行内式 行内式是在标 ...

  2. python trie

    Trie 库 https://github.com/pytries/marisa-trie/blob/master/docs/tutorial.rst http://marisa-trie.readt ...

  3. PythonStudy——集合 Set

    # 空集合:不能用{},因为用来标示空字典 s = set() print(s, type(s)) # 概念:# 1.set为可变类型 - 可增可删# 2.set为去重存储 - set中不能存放重复数 ...

  4. 用jquery得到select选中的值

    <select class="pushtype" name="push_type" onchange="pushType(this)" ...

  5. laravel路由别名

    在定义路由时使用数组键 as 指定路由名称: Route::get('user/profile', ['as' => 'profile', function () { // }]); 另外,还可 ...

  6. python的set处理二维数组转一维数组

    for splitValue in set(dataset[:, featureIndex].tolist()): 首先set是一个无序,无重复的数据结构,所以很多时候使用它来进行去重:但是set接收 ...

  7. 【转】Entity Framework 复杂类型

    为了说明什么是复杂属性,先举一个例子. public class CompanyAddress { public int ID { get; set; } public string CompanyN ...

  8. python import引入不同路径下的模块

    转载 python 包含子目录中的模块方法比较简单,关键是能够在sys.path里面找到通向模块文件的路径. 下面将具体介绍几种常用情况: (1)主程序与模块程序在同一目录下: 如下面程序结构: `- ...

  9. springboot整合mybatis之注解方式

    1. 创建maven项目,工程目录如下图 2. 在pom.xml文件中添加mybatis依赖. 3. 创建实体类,并生成construct方法,getter和setter方法.同时在数据库中创建对应的 ...

  10. maven的安装和配置

    这篇文章主要是对maven安装说明,以便后续翻阅,本人刚接触,请多见谅! 1.maven官网下载:http://maven.apache.org/download.cgi 2.解压到你想要放的路径里, ...