Heavy Transportation(最短路 + dp)
Time Limit:3000MS Memory Limit:30000KB 64bit IO Format:%I64d & %I64u
Description
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
/**
*Dijkstra + 静态邻接表 + 优先队列优化
*/ #include <iostream>
#include <deque>
#include <queue>
#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std; const int MAXV = ; //最大边数
const int INF = 0x3f3f3f3f; //最大权值
struct Edge
{
int to;
int link;
int w;
void set_val(int a, int b, int c){to = a, link = b, w = c;}
}edge[MAXV * MAXV >> ]; //存储边
int pre[MAXV]; struct Node
{
int v; //顶点的标号
int w; //顶点v到源点的最短路
Node(int a, int b) {v = a; w = b;}
void set_val(int a, int b) {v = a; w = b;}
}; //设立该结构体的目的:作为优先队列的结点
int d[MAXV]; //记录最短路
bool done[MAXV]; //记录是否已找到最短路,避免重复访问
int n, m; bool operator < (const Node& x, const Node& y)
{
return x.w < y.w;
} int main()
{
int t, ca = ;
scanf("%d", &t);
while(t--){
scanf("%d %d", &n, &m);
//建立静态邻接表
memset(pre, -, sizeof(pre));
for(int i = ; m--; ){
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
edge[i].set_val(a, pre[b], c);
pre[b] = i++;
edge[i].set_val(b, pre[a], c);
pre[a] = i++;
} //执行Dij算法,使用最小堆进行优化
memset(done, false, sizeof(done));
memset(d, , sizeof(d)); //d数组的初始化方式是关键!
d[] = INF;
priority_queue<Node> que;
que.push(Node(, d[])); //源点入队
done[] = true;
while(!que.empty()){
Node cur = que.top();
que.pop();
for(int i = pre[cur.v]; i != -; i = edge[i].link){
int to = edge[i].to;
if(!done[to] && d[to] < min(cur.w, edge[i].w)){
d[to] = min(cur.w, edge[i].w);
que.push(Node(to, d[to]));
}
}
} //输出结果
printf("Scenario #%d:\n%d\n\n", ca++, d[n]);
}
return ;
}
Heavy Transportation(最短路 + dp)的更多相关文章
- POJ 1797 Heavy Transportation (最短路)
		
Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 22440 Accepted: ...
 - POJ--1797 Heavy Transportation (最短路)
		
题目电波: POJ--1797 Heavy Transportation n点m条边, 求1到n最短边最大的路径的最短边长度 改进dijikstra,dist[i]数组保存源点到i点的最短边最大的路径 ...
 - POJ1797 Heavy Transportation —— 最短路变形
		
题目链接:http://poj.org/problem?id=1797 Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K T ...
 - POJ 1797 Heavy Transportation 最短路变形(dijkstra算法)
		
题目:click here 题意: 有n个城市,m条道路,在每条道路上有一个承载量,现在要求从1到n城市最大承载量,而最大承载量就是从城市1到城市n所有通路上的最大承载量.分析: 其实这个求最大边可以 ...
 - Heavy Transportation(最短路)
		
poj 1797 ——Heavy Transportation 思路: 这道题我们可以采用类似于求最短路径的方法,用一种新的“松弛操作”去取代原本的方法. 我们可以记录d[u]为运送货物到点j时最大可 ...
 - Heavy Transportation POJ 1797 最短路变形
		
Heavy Transportation POJ 1797 最短路变形 题意 原题链接 题意大体就是说在一个地图上,有n个城市,编号从1 2 3 ... n,m条路,每条路都有相应的承重能力,然后让你 ...
 - POJ 1797 Heavy Transportation(最大生成树/最短路变形)
		
传送门 Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 31882 Accept ...
 - (最短路) Heavy Transportation  --POJ--1797
		
链接: http://poj.org/problem?id=1797 Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K To ...
 - POJ 1797 ——Heavy Transportation——————【最短路、Dijkstra、最短边最大化】
		
Heavy Transportation Time Limit:3000MS Memory Limit:30000KB 64bit IO Format:%I64d & %I64 ...
 
随机推荐
- CSS/JS图片鼠标悬浮一道光闪过
			
看到有些网站logo鼠标悬浮上面的时候,会出现一道光,一闪而过,刚开始以为是gif图,已审查, 居然不是:现在就实现在这种效果: 先看看CSS实现的效果图: 看到没,就是这道刺眼的白光.... 啊 ...
 - 菜鸟日记-HTML
			
第一部分 HTML---Hyper Text Markup Language--超文本标记语言 1.HTML标准:<html> <head> 网页上的控制信息 <tit ...
 - Leetcode 190 Reverse Bits 位运算
			
反转二进制 class Solution { public: uint32_t reverseBits(uint32_t n) { uint32_t ans = ; ; i<; ++i,n &g ...
 - javascript设计模式与开发实践阅读笔记(7)——迭代器模式
			
迭代器模式:指提供一种方法顺序访问一个聚合对象中的各个元素,而又不需要暴露该对象的内部表示. 迭代器模式可以把迭代的过程从业务逻辑中分离出来,在使用迭代器模式之后,即使不关心对象的内部构造,也可以按顺 ...
 - javaweb回顾第六篇谈一谈Servlet线程安全问题
			
前言:前面说了很多关于Servlet的一些基础知识,这一篇主要说一下关于Servlet的线程安全问题. 1:多线程的Servlet模型 要想弄清Servlet线程安全我们必须先要明白Servlet实例 ...
 - 不能返回函数内部new分配的内存的引用
			
以前在开发电子秤接口动态库时,曾尝试在用于获取重量的函数外面定义一个字符串指针,然后作为参数传入函数内部,然后在函数内部new,用来输出函数执行过程中发生的错误.但是总是出错,没有找到原因,后来无意中 ...
 - Clojure上手
			
Clojure,这是什么鬼?一门基于JVM(现在也有基于.NET CLR的了:Clojure CLR) 的函数式编程语言.在JVM平台运行的时候,会被编译为JVM的字节码进行运算..为什么要学它?其设 ...
 - C#通过SQL 添加,删除,或者修改表名。
			
这是我在 https://forums.asp.net/t/2106051.aspx?Create+Dynamic+table+in+SQL+using+C+ 的回复,如果其他人需要,可以参考 如果你 ...
 - Android中使用自定义View实现下载进度的显示
			
一般有下载功能的应用都会有这样一个场景,需要一个图标来标识不同的状态.之前在公司的项目中写过一个,今天抽空来整理一下. 一般下载都会有这么几种状态:未开始.等待.正在下载.下载结束,当然有时候会有下载 ...
 - eclipse快捷键调试总结【转】
			
http://www.cnblogs.com/yxnchinahlj/archive/2012/02/22/2363542.html (1)Ctrl+M --切换窗口的大小(2)Ctrl+Q --跳到 ...