题意

给你n个点,1为起点,n为终点,要求所有1到n所有路径中每条路径上最小值的最最值。


思路

不想打最短路
跑一边最大生成树,再扫一遍1到n的路径,取最小值即可,类似Frogger POJ - 2253,代码都没怎么改


常数巨大的丑陋代码

# include <stdio.h>
# include <stdlib.h>
# include <iostream>
# include <string.h>
# include <math.h>
# include <algorithm>
using namespace std; # define IL inline
# define RG register
# define UN unsigned
# define ll long long
# define rep(i, a, b) for(RG int i = a; i <= b; i++)
# define per(i, a, b) for(RG int i = b; i >= a; i--)
# define uev(e, u) for(RG int e = ft[u]; e != -1; e = edge[e].nt)
# define mem(a, b) memset(a, b, sizeof(a))
# define max(a, b) (((a) > (b)) ? (a) : (b))
# define min(a, b) (((a) < (b)) ? (a) : (b))
# define Swap(a, b) a ^= b, b ^= a, a ^= b; IL ll Get(){
RG char c = '!'; RG ll x = 0, z = 1;
while(c != '-' && (c < '0' || c > '9')) c = getchar();
if(c == '-') z = -1, c = getchar();
while(c >= '0' && c <= '9') x = x*10+c-'0', c = getchar();
return x*z;
} const int MAXN = 1000001;
int ft[MAXN], n, cnt, vis[MAXN], fa[MAXN], m, ans = 2147483647;
struct Edge{
int to, nt, f;
} edge[MAXN<<1];
struct _Edge{
int u, v, f;
IL bool operator < (_Edge b) const{
return f > b.f;
}
} _edge[MAXN]; IL void Add(RG int u, RG int v, RG int f){
edge[cnt] = (Edge){v, ft[u], f}; ft[u] = cnt++;
} IL int Find(RG int x){
return fa[x] == x ? x : Find(fa[x]);
} IL void Kruskal(){
sort(_edge + 1, _edge + m + 1);
RG int t = 0;
rep(i, 1, m){
if(t == n - 1) break;
RG int u = Find(_edge[i].u), v = Find(_edge[i].v);
if(u != v){
t++; fa[u] = v;
Add(u, v, _edge[i].f); Add(v, u, _edge[i].f);
}
}
} IL void Dfs(RG int u, RG int ans1){
if(u == n) ans = ans1;
uev(e, u){
RG int v = edge[e].to;
if(vis[v]) continue;
vis[v] = 1;
RG int f = min(ans1, edge[e].f);
Dfs(v, f);
}
} int main(){
RG int T = Get();
rep(t, 1, T){
n = Get(); m = Get();
mem(ft, -1); ans = 2147483647; cnt = 0;
rep(i, 1, m){
RG int u = Get(), v = Get(), f = Get();
_edge[i] = (_Edge){u, v, f};
}
rep(i, 1, n) fa[i] = i;
Kruskal();
mem(vis, 0); vis[1] = 1;
Dfs(1, ans);
printf("Scenario #%d:\n%d\n\n", t, ans);
}
return 0;
}

Heavy Transportation POJ - 1797的更多相关文章

  1. Heavy Transportation POJ 1797 最短路变形

    Heavy Transportation POJ 1797 最短路变形 题意 原题链接 题意大体就是说在一个地图上,有n个城市,编号从1 2 3 ... n,m条路,每条路都有相应的承重能力,然后让你 ...

  2. kuangbin专题专题四 Heavy Transportation POJ - 1797

    题目链接:https://vjudge.net/problem/POJ-1797 思路:请参考我列出的另一个题目,和这个题目要求的值相反,另一个清楚后,这个写的解释就明白了. 另一个类似题目的博客:h ...

  3. POJ 1797 Heavy Transportation (Dijkstra变形)

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

  4. POJ 1797 Heavy Transportation

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

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

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

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

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

  7. POJ.1797 Heavy Transportation (Dijkstra变形)

    POJ.1797 Heavy Transportation (Dijkstra变形) 题意分析 给出n个点,m条边的城市网络,其中 x y d 代表由x到y(或由y到x)的公路所能承受的最大重量为d, ...

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

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

  9. POJ 1797 Heavy Transportation SPFA变形

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

随机推荐

  1. nodejs开启服务器端口

    var http = require('http'); var server = http.createServer(function(req, res) { res.writeHead(200, { ...

  2. mac 上node.js环境的安装与测试

    如果大家之前做过web服务器的人都知道,nginx+lua与现在流行的Node.js都是可以做web服务器的,前者在程序的写法和配置上要比后者麻烦,但用起来都是差不多.在这里建议大家如果对lua脚本语 ...

  3. Linux-安装FFmpeg

    FFmpeg官网:http://www.ffmpeg.org 官网介绍 FFmpeg is the leading multimedia framework, able to decode, enco ...

  4. 35 个 jQuery 小技巧

    1. 禁止右键点击 $(document).ready(function(){ $(document).bind("contextmenu",function(e){ return ...

  5. 深入java虚拟机学习 -- 类的加载机制

    当看到"类的加载机制",肯定很多人都在想我平时也不接触啊,工作中无非就是写代码,不会了可以百度,至于类,jvm是怎么加载的我一点也不需要关心.在我刚开始工作的时候也觉得这些底层的内 ...

  6. 利用Azure嵌套虚拟化,解决公有云上机器不能启动的问题

    很多时候我们都会碰到因为意外重启,机器硬盘被损坏导致无法启动,或者是因为各种原因Windows上的RDP服务启动不了,Linux上的SSH无法链接等等问题.碰到这种问题基本上很难解决以前都是将VHD下 ...

  7. 01. SELECT显示和PRINT打印超长的字符

    从SQL Server 2005开始,引入了varchar(max) / nvarchar(max) 数据类型,表中可不使用LOB数据类型,从而突破单列8000 / 4000字符的限制,动态SQL也可 ...

  8. Mysql引擎中MyISAM和InnoDB的区别有哪些?

    简单的概括一下 InnoDB:支持事务处理等不加锁读取支持外键支持行锁不支持FULLTEXT类型的索引不保存表的具体行数,扫描表来计算有多少行DELETE 表时,是一行一行的删除InnoDB 把数据和 ...

  9. Batch Normalization&Dropout浅析

    一. Batch Normalization 对于深度神经网络,训练起来有时很难拟合,可以使用更先进的优化算法,例如:SGD+momentum.RMSProp.Adam等算法.另一种策略则是高改变网络 ...

  10. C++ stl 怎么打印内存内容?

    #include <iostream> #include <string> #include <sstream> #include <iomanip> ...