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 ...
随机推荐
- 空间插值文献阅读(Geostatistical approaches for incorporating elevation into the spatial interpolation of rainfall)
空间插值技术应用必读论文---P. Goovaerts, Geostatistical approaches for incorporating elevation into the spatial ...
- JavaScript、for循环语句知识巩固,while(){}语句以及do{}while()语句以及switch()语句
一.for循环语句练习 关于for循环存在的两个问题类型 穷举:在不知道什么情况下才真的寻要我们的结果,自能让我们一个个走一遍. 迭代:在现有的条件根据规律不断求解,中间情况,最终推测出来的结果 1. ...
- 更新日志 - BugHD 全面开放 API 文档
Hey, 上周 BugHD 全面更新 API 文档,上线一些新的功能,让你可以轻松掌控 Crash ,更方便分享.定位和解决.同时,新版 fir.im 也有所优化,希望你们会喜欢. 具体如下: 开放 ...
- PLSQL查询表是否被锁定(转)
PLSQL查询表是否被锁定(转) http://blog.sina.com.cn/s/blog_70717ff00100qb85.html (2011-05-08 13:13:06) 转载▼ 标签: ...
- main方法中声明8种基本数据类型的变量并赋值
main方法中声明8种基本数据类型的变量并赋值 char→ int→ long→ float→ double byte→ short→
- sqlserver自定义函数的创建与调用
sqlserver中有系统提供的函数,像avg.sum.getdate()等,用户还可以自定义函数. 用户自定义的函数包括:标量函数和表值函数,其中标量函数和系统函数的用法一样,表值函数根据主体的定义 ...
- iptables防火墙原理详解
1. netfilter与iptables Netfilter是由Rusty Russell提出的Linux 2.4内核防火墙框架,该框架既简洁又灵活,可实现安全策略应用中的许多功能,如数据包过滤.数 ...
- AP6181 正基 WIFI 模块
a. Module size: 12*12mm (pin to pin compatible) Package: Stamp type 44pins AP6181: WiFiAP6210: WiFi/ ...
- CCNA实验4:HDLC和PPP
一.HDLC封装 router9和11上分别配置s0/0如下 conf t int s0/0 encapsulation hdlc do show int s0/0 ip address x.x.x. ...
- 关于NMF(Non-negative Matrix Factorization )
著名的科学杂志<Nature>于1999年刊登了两位科学家D.D.Lee和H.S.Seung对数学中非负矩阵研究的突出成果.该文提出了一种新的矩阵分解思想――非负矩阵分解(Non-nega ...