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 字典自动生成模型

    在实际开发中,我们经常需要根据字典来建模型.每次都打那么一串代码,想想也是挺恶心的.可以自己给NSDictionary写一个分类,进行属性生成. NSDictionary+Property.h #im ...

  2. autocomplete实现联想输入,自动补全

    jQuery.AutoComplete是一个基于jQuery的自动补全插件.借助于jQuery优秀的跨浏览器特性,可以兼容Chrome/IE/Firefox/Opera/Safari等多种浏览器. 特 ...

  3. atitit.解决struts2 SpringObjectFactory.getClassInstance NullPointerException

    atitit.解决struts2 SpringObjectFactory.getClassInstance NullPointerException #--现象 java.lang.NullPoint ...

  4. python函数的参数

    代码: # coding=utf8 # 可以传入任何个参数 def calc(*numbers): sum = 0 for n in numbers: sum = sum + n * n return ...

  5. Ubuntu 安装JDK步骤 ,提示没有那个文件或目录

    作为一个程序员,配置环境是最基本的功夫,然而我却捣鼓了一下午,包括安装Ubuntu,安装JDK和配置环境变量. 简单记录下自己的安装过程: 1  下载JDK tar包,使用tar -xzvf jdk* ...

  6. Leetcode-121 Best Time to Buy and Sell Stock

    #121   Best Time to Buy and Sell Stock Say you have an array for which the ith element is the price ...

  7. (转)TRANSFORM_TEX详解

    原创文章如需转载请注明:转载自风宇冲Unity3D教程学院 特别讲:常见问题回答   本讲会陆续补充一些问题的解答. 问: (1) TRANSFORM_TEX是做什么的 (2)float4 _Main ...

  8. 转:电子取证中AVI文件的文件雕复

    电子取证中AVI文件的文件雕复 收藏本文 分享 1引言在电子取证工作中,恢复数字设备中被删除的数据是极为重要的工作之一,恢复数据又分依赖系统元信息的传统数据恢复技术和不依赖系统元信息的文件雕刻.文件雕 ...

  9. RPC和NFS

    参考:http://eduunix.ccut.edu.cn/index2/html/linux/OReilly.SUSE.Linux.Jul.2006/059610183X/suselinux-CHP ...

  10. c/c++ 输入输出缓冲区

    关于缓冲区的详细介绍,请参考 C++编程对缓冲区的理解 CPP的输入输出流和缓冲区 c++输出缓冲区刷新   (1)c++中cin.cout,cerr和c的stdin.stdout.stderr都是同 ...