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 ...
随机推荐
- [Java拾遗四]JavaWeb基础之Servlet_Request&&Response
今天来回顾下之前学过Servle的Resquest以及Response的知识.1,Request和Response技术: rr的作用: request是请求,封装用户的请求信息.若 ...
- paip.输入法编程--英文ati化By音标原理与中文atiEn处理流程 python 代码为例
paip.输入法编程--英文ati化By音标原理与中文atiEn处理流程 python 代码为例 #---目标 1. en vs enPHati 2.en vs enPhAtiSmp 3.cn vs ...
- MVC 添加 httpHandlers 支持 .aspx 页面访问
<?xml version="1.0"?> <!-- For more information on how to configure your ASP.NET ...
- 固定表头/锁定前几列的代码参考[JS篇]
引语:做有难度的事情,才是成长最快的时候.前段时间,接了一个公司的稍微大点的项目,急着赶进度,本人又没有独立带过队,因此,把自己给搞懵逼了.总是没有多余的时间来做自己想做的事,而且,经常把工作带入生活 ...
- java集合——题4,6
4.(List)写一个函数reverseList,该函数能够接受一个List,然后把该List 倒序排列. 例如: List list = new ArrayList(); list.add(“Hel ...
- JavaWeb学习总结(十二)——Session
一.Session简单介绍 在WEB开发中,服务器可以为每个用户浏览器创建一个会话对象(session对象),注意:一个浏览器独占一个session对象(默认情况下).因此,在需要保存用户数据时,服务 ...
- java 调用微信截图工具
- 推荐算法——距离算法
本文内容 用户评分表 曼哈顿(Manhattan)距离 欧式(Euclidean)距离 余弦相似度(cos simliarity) 推荐算法以及数据挖掘算法,计算"距离"是必须的~ ...
- Android开发之蓝牙--扫描已经配对的蓝牙设备
一. 什么是蓝牙(Bluetooth)? 1.1 BuleTooth是目前使用最广泛的无线通信协议 1.2 主要针对短距离设备通讯(10m) 1.3 常用于连接耳机,鼠标和移动通讯设备等. 二. ...
- 解决genemotion模拟器冲突导致的Android Studio无法启动ADB的问题
首先命令行下运行 adb nodaemon server ./adb nodaemon server (Mac OSX) 如果出现错误: error: could not install *smart ...