(简单) POJ 1797 Heavy Transportation,Dijkstra。
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.
#include<iostream>
#include<cstring>
#include<queue>
#include<vector>
#include<cstdio> #define min(a,b) (a<b ? a:b) using namespace std; const int INF=10e8;
const int MaxN=; struct Node
{
int v,val; Node(int _v=,int _val=):v(_v),val(_val) {}
bool operator < (const Node &a) const
{
return val<a.val;
}
}; struct Edge
{
int v,cost; Edge(int _v=,int _cost=):v(_v),cost(_cost) {}
}; vector <Edge> E[MaxN]; void Dijkstra(int lowcost[],int n,int start)
{
priority_queue <Node> que;
Node qtemp;
int len;
int u,v,cost; for(int i=;i<=n;++i)
{
lowcost[i]=;
}
lowcost[start]=INF; que.push(Node(start,INF)); while(!que.empty())
{
qtemp=que.top();
que.pop(); u=qtemp.v; len=E[u].size(); for(int i=;i<len;++i)
{
v=E[u][i].v;
cost=E[u][i].cost; if(min(cost,lowcost[u])>lowcost[v])
{
lowcost[v]=min(cost,lowcost[u]);
que.push(Node(v,lowcost[v]));
}
}
}
} inline void addEdge(int u,int v,int c)
{
E[u].push_back(Edge(v,c));
} int ans[MaxN]; int main()
{
// ios::sync_with_stdio(false); int N,M;
int a,b,c;
int T; scanf("%d",&T); for(int cas=;cas<=T;++cas)
{
scanf("%d %d",&N,&M); for(int i=;i<=N;++i)
E[i].clear(); for(int i=;i<=M;++i)
{
scanf("%d %d %d",&a,&b,&c); addEdge(a,b,c);
addEdge(b,a,c);
} Dijkstra(ans,N,); printf("Scenario #%d:\n",cas);
printf("%d\n\n",ans[N]);
} return ;
}
(简单) POJ 1797 Heavy Transportation,Dijkstra。的更多相关文章
- POJ.1797 Heavy Transportation (Dijkstra变形)
POJ.1797 Heavy Transportation (Dijkstra变形) 题意分析 给出n个点,m条边的城市网络,其中 x y d 代表由x到y(或由y到x)的公路所能承受的最大重量为d, ...
- POJ 1797 Heavy Transportation (Dijkstra)
题目链接:POJ 1797 Description Background Hugo Heavy is happy. After the breakdown of the Cargolifter pro ...
- POJ 1797 Heavy Transportation / SCU 1819 Heavy Transportation (图论,最短路径)
POJ 1797 Heavy Transportation / SCU 1819 Heavy Transportation (图论,最短路径) Description Background Hugo ...
- poj 1797 Heavy Transportation(最大生成树)
poj 1797 Heavy Transportation Description Background Hugo Heavy is happy. After the breakdown of the ...
- POJ 1797 Heavy Transportation
题目链接:http://poj.org/problem?id=1797 Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K T ...
- POJ 1797 Heavy Transportation SPFA变形
原题链接:http://poj.org/problem?id=1797 Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K T ...
- POJ 1797 Heavy Transportation (Dijkstra变形)
F - Heavy Transportation Time Limit:3000MS Memory Limit:30000KB 64bit IO Format:%I64d & ...
- POJ 1797 ——Heavy Transportation——————【最短路、Dijkstra、最短边最大化】
Heavy Transportation Time Limit:3000MS Memory Limit:30000KB 64bit IO Format:%I64d & %I64 ...
- POJ 1797 Heavy Transportation (dijkstra 最小边最大)
Heavy Transportation 题目链接: http://acm.hust.edu.cn/vjudge/contest/66569#problem/A Description Backgro ...
随机推荐
- on使用详解
on()是bind(),live(),delegate()的替代品,1.7及1.7以后使用on() bind() 绑定元素 live() 为元素附加事件,匹配选择器的当前及未来的元素(比如由脚本创建的 ...
- vi编辑器常见命令的使用
Linux下的文本编辑器有很多种,vi 是最常用的,也是各版本Linux的标配.注意,vi 仅仅是一个文本编辑器,可以给字符着色,可以自动补全,但是不像 Windows 下的 word 有排版功能. ...
- Ubuntu下修改DNS重启也能用的方法
1.通过修改:/etc/resolvconf/resolv.conf.d/base(这个文件默认是空的)实现 内容填上需要修改的nameserver
- android之相机开发
http://blog.csdn.net/jason0539/article/details/10125017 android之相机开发 分类: android 基础知识2013-08-20 22: ...
- PullToRefreshGridView上拉加载、下拉刷新
eclipse中的项目: //注意:此刷新功能是使用的第三方的PullToRefreshScrollView,因此需要导入第三方library作为依赖 步骤:导入第三方library,依赖:点击你的应 ...
- std::function 测试
#ifndef __HELLOWORLD_SCENE_H__ #define __HELLOWORLD_SCENE_H__ #include "cocos2d.h" typedef ...
- cocos2d3.8.1 使用prebuild提升发布android速度
1.生成cocos prebuild库 cocos gen-libs -m debug或 cocos gen-libs -m release 2.使用命令创建test项目 cocos new test ...
- OpenCv的Java,C++开发环境配置
1.OpenCV 下载及安装配置 opencv的下载地址:http://opencv.org/downloads.html 最新版本:opencv3.0.0 注意:支持的visual studio20 ...
- 上传Android或Java库到Maven central repository(转载)
主要介绍利用Sonatype将jar或aar提交到Maven的中央仓库. 是不是希望将自己的jar或是aar传到maven官方库中,在The Central Repository中可以被其他人搜索使用 ...
- 最简单的epoll的使用范例 : 监听 标准输入 ,并将数据回显到终端
#include<stdio.h>#include<stdlib.h>#include<unistd.h>#include<sys/epoll.h> # ...