Heavy Transportation

Time Limit:3000MS     Memory Limit:30000KB     64bit IO Format:%I64d & %I64u

Description

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

The first line contains the number of scenarios (city plans). For each city the number n of street crossings (1 <= n <= 1000) and number m of streets are given on the first line. The following m lines contain triples of integers specifying start and end crossing of the street and the maximum allowed weight, which is positive and not larger than 1000000. There will be at most one street between each pair of crossings.

Output

The output for every scenario begins with a line containing "Scenario #i:", where i is the number of the scenario starting at 1. Then print a single line containing the maximum allowed weight that Hugo can transport to the customer. Terminate the output for the scenario with a blank line.
 
不用邻接表会超时。注意输出格式。
 
AC Code:
 /**
*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)的更多相关文章

  1. POJ 1797 Heavy Transportation (最短路)

    Heavy Transportation Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 22440   Accepted:  ...

  2. POJ--1797 Heavy Transportation (最短路)

    题目电波: POJ--1797 Heavy Transportation n点m条边, 求1到n最短边最大的路径的最短边长度 改进dijikstra,dist[i]数组保存源点到i点的最短边最大的路径 ...

  3. POJ1797 Heavy Transportation —— 最短路变形

    题目链接:http://poj.org/problem?id=1797 Heavy Transportation Time Limit: 3000MS   Memory Limit: 30000K T ...

  4. POJ 1797 Heavy Transportation 最短路变形(dijkstra算法)

    题目:click here 题意: 有n个城市,m条道路,在每条道路上有一个承载量,现在要求从1到n城市最大承载量,而最大承载量就是从城市1到城市n所有通路上的最大承载量.分析: 其实这个求最大边可以 ...

  5. Heavy Transportation(最短路)

    poj 1797 ——Heavy Transportation 思路: 这道题我们可以采用类似于求最短路径的方法,用一种新的“松弛操作”去取代原本的方法. 我们可以记录d[u]为运送货物到点j时最大可 ...

  6. Heavy Transportation POJ 1797 最短路变形

    Heavy Transportation POJ 1797 最短路变形 题意 原题链接 题意大体就是说在一个地图上,有n个城市,编号从1 2 3 ... n,m条路,每条路都有相应的承重能力,然后让你 ...

  7. POJ 1797 Heavy Transportation(最大生成树/最短路变形)

    传送门 Heavy Transportation Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 31882   Accept ...

  8. (最短路) Heavy Transportation --POJ--1797

    链接: http://poj.org/problem?id=1797 Heavy Transportation Time Limit: 3000MS   Memory Limit: 30000K To ...

  9. POJ 1797 ——Heavy Transportation——————【最短路、Dijkstra、最短边最大化】

    Heavy Transportation Time Limit:3000MS     Memory Limit:30000KB     64bit IO Format:%I64d & %I64 ...

随机推荐

  1. iOS开发----地图与导航--定位和位置信息获取

    要实现地图.导航功能,往往需要先熟悉定位功能,在iOS中通过Core Location框架进行定位操作.Core Location自身可以单独使用,和地图开发框架MapKit完全是独立的,但是往往地图 ...

  2. 《软件性能测试与LoadRunner实战教程》新书上市

    作者前三本书<软件性能测试与LoadRunner实战>.<精通软件性能测试与LoadRunner实战>和<精通软件性能测试与LoadRunner最佳实战>面市后,受 ...

  3. C#创建唯一的订单号, 考虑时间因素

    主要是想把日期和其它因素考虑进来. 使用RNGCryptoServiceProvider类创建唯一的最多8位数字符串. private static string GetUniqueKey() { ; ...

  4. Java的自动装箱和拆箱的简单讲解

     装箱就是把基础类型封装成一个类.比如把int封装成Integer,这时你就不能把他当成一个数了,而是一个类了,对他的操作就需要用它的方法了. 拆箱就是把类转换成基础类型.比如你算个加法什么的是不能用 ...

  5. [SRS流媒体]RTMP/HLS 直播服务器simple-rtmp-server安装

    一个采用MIT协议授权的国产的简单的RTMP/HLS 直播服务器,其核心的价值理念在于简单高效. 使用方法: tep 1: build srs tar xf simple-rtmp-server-*. ...

  6. 使用 dbms_xplan.display 按照 plan_hash_value 查执行计划的方法

    dbms_xplan.display_* 能按照 plan_hash_value 只有 display_awr 方法,如果这个SQL PLAN 刚刚生成,没有写入到AWR怎么办呢? 可以将 V$SQL ...

  7. 【Vegas原创】Mysql绿色版安装方法

    所谓的绿色版,就是没有installer的MySQL,完全需要靠人工来操作,好处是,重装系统后,只要再做一次本次配置,即可使用. 具体操作方法: 1,设置系统环境变量, 在Path中添加 D:\mys ...

  8. 使用 SELinux 和 Smack 增强轻量级容器

    http://www.bitscn.com/os/linux/200904/158771.html 安全 Linux 容器实现指南 轻量级容器 又称作 Virtual Private Servers ...

  9. spring整合activemq发送MQ消息[Topic模式]实例

    Topic模式消息发送实例 1.pom引入 <dependency> <groupId>junit</groupId> <artifactId>juni ...

  10. Scala 深入浅出实战经典 第78讲:Type与Class实战详解

    王家林亲授<DT大数据梦工厂>大数据实战视频 Scala 深入浅出实战经典(1-87讲)完整视频.PPT.代码下载: 百度云盘:http://pan.baidu.com/s/1c0noOt ...