Heavy Transportation POJ - 1797
题意
给你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的更多相关文章
- Heavy Transportation POJ 1797 最短路变形
Heavy Transportation POJ 1797 最短路变形 题意 原题链接 题意大体就是说在一个地图上,有n个城市,编号从1 2 3 ... n,m条路,每条路都有相应的承重能力,然后让你 ...
- kuangbin专题专题四 Heavy Transportation POJ - 1797
题目链接:https://vjudge.net/problem/POJ-1797 思路:请参考我列出的另一个题目,和这个题目要求的值相反,另一个清楚后,这个写的解释就明白了. 另一个类似题目的博客:h ...
- POJ 1797 Heavy Transportation (Dijkstra变形)
F - Heavy Transportation Time Limit:3000MS Memory Limit:30000KB 64bit IO Format:%I64d & ...
- POJ 1797 Heavy Transportation
题目链接:http://poj.org/problem?id=1797 Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K T ...
- poj 1797 Heavy Transportation(最大生成树)
poj 1797 Heavy Transportation Description Background Hugo Heavy is happy. After the breakdown of the ...
- POJ 1797 Heavy Transportation / SCU 1819 Heavy Transportation (图论,最短路径)
POJ 1797 Heavy Transportation / SCU 1819 Heavy Transportation (图论,最短路径) Description Background Hugo ...
- POJ.1797 Heavy Transportation (Dijkstra变形)
POJ.1797 Heavy Transportation (Dijkstra变形) 题意分析 给出n个点,m条边的城市网络,其中 x y d 代表由x到y(或由y到x)的公路所能承受的最大重量为d, ...
- POJ 1797 ——Heavy Transportation——————【最短路、Dijkstra、最短边最大化】
Heavy Transportation Time Limit:3000MS Memory Limit:30000KB 64bit IO Format:%I64d & %I64 ...
- POJ 1797 Heavy Transportation SPFA变形
原题链接:http://poj.org/problem?id=1797 Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K T ...
随机推荐
- c# 利用IMap 收取163邮件
最近我要做一个爬虫.这个爬虫需要如下几个步骤: 1 填写注册内容(需要邮箱注册) 2 过拖拽验证码(geetest) 3 注册成功会给邮箱发一封确认邮箱 4 点击确认邮箱中的链接 完成注册 我这里就采 ...
- 记录一次CentOS环境升级Python2.6到Python2.7并安装最新版pip
背景介绍 一次实验中需要安装python-etcd包.安装这个包时要求的python和pip版本比目前系统的版本高. 系统是centos6.6 64位 1 2 3 4 5 6 7 [root@m ...
- 整理的linux面试运维题
如何在非交互模式下把 /home/example/下所有.conf文件中的 192.168.0.2 改成 db01 ? find /home/example/ -type f -name &quo ...
- 同步博客—CSDN推广
niiickのCSDN 用CSDN也有几个月了 其实一开始有人让我转到博客园我是拒绝的 (毕竟强迫症接受不了一边博客只有一半= =) 不过最近有幸观赏了某位dalao的博客园 发现没有广告好棒!!!设 ...
- vue框架-学习记录
前段时间在做vue项目时,遇到挺多问题,想简单总结一下: 1.关于父组件,子组件的通信 网上有很多这方面的讲解,讲解也比较细致,我主要总结了自己在项目中需要的: [1]父组件-子组件 也就是" ...
- Django——ContentType及ContentType-signals的使用
一.ContentType 在django中,有一个记录了项目中所有model元数据的表,就是ContentType,表中一条记录对应着一个存在的model,所以可以通过一个ContentType表的 ...
- iOS视频直播
视频直播技术点 视频直播,可以分为 采集,前处理,编码,传输, 服务器处理,解码,渲染 采集: iOS系统因为软硬件种类不多, 硬件适配性比较好, 所以比较简单. 而Android端市面上机型众多, ...
- LeetCode第六天
第六天 30.(219) Contains Duplicate II JAVA class Solution { public boolean containsNearbyDuplicate(int[ ...
- Android设备唯一码的获取
Android设备唯一码的获取 UTDID是集团无线设备统一ID方案,目的是给每一台设备一个ID,作为唯一标识.UTDID由客户端生成,并在设备中各个客户端之间共享.UTDID的生成中包含时间戳和随机 ...
- 基于Jenkins+Git+Gradle的Android持续集成
本文参考了: http://my.oschina.net/uboluo/blog/157483 http://java.dzone.com/articles/automating-continuous ...