最短路 || POJ 1797 Heavy Transportation
Background
Hugo Heavy is happy. After the breakdown of the Cargolifter project he can now expand business. But he needs a clever man who tells him whether there really is a way from the place his customer has build his giant steel crane to the place where it is needed on which all streets can carry the weight.
Fortunately he already has a plan of the city with all streets and bridges and all the allowed weights.Unfortunately he has no idea how to find the the maximum weight capacity in order to tell his customer how heavy the crane may become. But you surely know.
Problem
You are given the plan of the city, described by the streets (with weight limits) between the crossings, which are numbered from 1 to n. Your task is to find the maximum weight that can be transported from crossing 1 (Hugo's place) to crossing n (the customer's place). You may assume that there is at least one path. All streets can be travelled in both directions.
Input
Output
Sample Input
1
3 3
1 2 3
1 3 4
2 3 5
Sample Output
Scenario #1:
4
┉┉ ∞ ∞ ┉┉┉┉ ∞ ∞ ┉┉┉┉┉ ∞ ∞ ┉┉┉┉ ∞ ∞ ┉┉┉┉┉ ∞ ∞ ┉┉┉┉ ∞ ∞ ┉┉┉┉┉ ∞ ∞ ┉┉┉┉ ∞ ∞ ┉┉┉┉┉ ∞ ∞ ┉┉┉┉ ∞ ∞ ┉┉┉┉┉ ∞ ∞ ┉┉┉┉ ∞ ∞ ┉┉┉┉┉ ∞ ∞ ┉┉┉┉ ∞ ∞ ┉┉┉┉┉ ∞ ∞ ┉┉┉┉ ∞ ∞ ┉┉┉
题意:每条边上都有一个权值,表示这条边上最多运w重的物品,问从1到n一次最多能运多重的物品
思路:其实就是求从1到n的路上的最短边的最大值
考虑最短路的想法,dist[u]表示从1到u的最短边的最大值,当dist[v] < min(dist[u] , l[i].d)时,表示从u经过这条边到v,最短边的最大值要比直接到v大,所以更新dist[v]
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
using namespace std;
#define SZ 1000010
#define INF 1e9+10
int head[SZ],nxt[SZ],tot = , n;
struct edge{
int t,d;
}l[SZ];
void build(int f,int t,int d){
l[++ tot] = (edge){t,d};
nxt[tot] = head[f];
head[f] = tot;
}
int dist[], vis[];
struct node
{
int u,d;
}now;
priority_queue<node> q;
bool operator < (node a, node b) {return a.d < b.d; }
int dij(int s, int e)
{
for(int i = ; i <= n; i++) dist[i] = , vis[i] = ;
while(q.size()) q.pop();
q.push((node){s,});
dist[s] = INF;
while(q.size())
{
int u = q.top().u;
q.pop();
if(vis[u]) continue;
vis[u] = ;
for(int i = head[u];i;i = nxt[i])
{
int v = l[i].t;
if(dist[v] < min(dist[u], l[i].d))
{
dist[v] = min(dist[u], l[i].d);
q.push((node){v,dist[v]});
}
}
}
return dist[e];
} int main()
{
int T, tt = ;
scanf("%d", &T);
while(T--)
{
int m;
scanf("%d %d", &n, &m);
tot = ;
memset(head, , sizeof(head));
memset(nxt, , sizeof(nxt));
while(m--)
{
int f, t, d;
scanf("%d %d %d", &f, &t, &d);
build(f, t, d);
build(t, f, d);
}
printf("Scenario #%d:\n", tt++);
printf("%d\n", dij(, n));
printf("\n");
}
return ;
}
最短路 || POJ 1797 Heavy Transportation的更多相关文章
- 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
题目链接:http://poj.org/problem?id=1797 Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K T ...
- POJ 1797 Heavy Transportation SPFA变形
原题链接:http://poj.org/problem?id=1797 Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K T ...
- POJ 1797 ——Heavy Transportation——————【最短路、Dijkstra、最短边最大化】
Heavy Transportation Time Limit:3000MS Memory Limit:30000KB 64bit IO Format:%I64d & %I64 ...
- POJ 1797 Heavy Transportation(最大生成树/最短路变形)
传送门 Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 31882 Accept ...
- POJ 1797 Heavy Transportation (最短路)
Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 22440 Accepted: ...
- POJ 1797 Heavy Transportation (Dijkstra变形)
F - Heavy Transportation Time Limit:3000MS Memory Limit:30000KB 64bit IO Format:%I64d & ...
随机推荐
- bzoj4750
单调栈+前缀和 max很明显用单调栈搞,但是异或和呢?异或和我们拆位,对于每段区间的异或和[l[i]-i],[i,r[i]]答案就是0->1,1->0的乘积,但是统计的时候事实上是[l[i ...
- 【旧文章搬运】暴搜内存查找PE镜像
原文发表于百度空间,2008-7-28========================================================================== 前面介绍了修 ...
- 笔记本创建wifi热点
如何在Win8系统上建立WIFI热点 | 浏览: 2511 | 更新: 2013-04-10 01:55 | 标签: win8 59 28 全文阅读分步阅读 步骤 1 2 3 4 5 6 7 8 ...
- 斯坦福CS231n—深度学习与计算机视觉----学习笔记 课时26&&27
课时26 图像分割与注意力模型(上) 语义分割:我们有输入图像和固定的几个图像分类,任务是我们想要输入一个图像,然后我们要标记每个像素所属的标签为固定数据类中的一个 使用卷积神经,网络为每个小区块进行 ...
- 20170406-ms
Interval 间隔 revoke v撤销 alert adj 警觉的 n警报
- hdoj5003【wa水】
蜜汁wa,蜜汁wa,少了个\n------ #include<bits/stdc++.h> using namespace std; typedef long long LL; typed ...
- 拓扑排序+DFS(POJ1270)
[日后练手](非解题) 拓扑排序+DFS(POJ1270) #include<stdio.h> #include<iostream> #include<cstdio> ...
- MySQL与MongoDB的区别
一.MongoDB简介 什么是MongoDB ?MongoDB 是由C++语言编写的,是一个基于分布式文件存储的开源数据库系统.在高负载的情况下,添加更多的节点,可以保证服务器性能.MongoDB 旨 ...
- BZOJ4974(给Next求最小字典序原串)
输入给出了最小循环节长度,暗示next数组. 然后自己按照自己的kmp板子逆着来一遍就好. ; int n, a, Next[maxn]; char str[maxn]; ]; int main() ...
- C语言精确微秒级的延时
//----------------------------------------------------------------------------- // Delay_us //------ ...