POJ1797 Heavy Transportation —— 最短路变形
题目链接:http://poj.org/problem?id=1797
| Time Limit: 3000MS | Memory Limit: 30000K | |
| Total Submissions: 39999 | Accepted: 10515 |
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
Sample Input
1
3 3
1 2 3
1 3 4
2 3 5
Sample Output
Scenario #1:
4
Source
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <set>
#define rep(i,a,n) for(int (i) = a; (i)<=(n); (i)++)
#define ms(a,b) memset((a),(b),sizeof((a)))
using namespace std;
typedef long long LL;
const double EPS = 1e-;
const int INF = 2e9;
const LL LNF = 9e18;
const int MOD = 1e9+;
const int MAXN = 1e3+; int n, m; struct edge
{
int to, w, next;
}edge[MAXN*MAXN];
int cnt, head[MAXN]; void addedge(int u, int v, int w)
{
edge[cnt].to = v;
edge[cnt].w = w;
edge[cnt].next = head[u];
head[u] = cnt++;
} void init()
{
cnt = ;
memset(head, -, sizeof(head));
} int dis[MAXN];
bool vis[MAXN];
void dijkstra(int st)
{
memset(vis, , sizeof(vis));
for(int i = ; i<=n; i++)
dis[i] = (i==st?INF:); for(int i = ; i<=n; i++)
{
int k, maxx = ;
for(int j = ; j<=n; j++)
if(!vis[j] && dis[j]>maxx)
maxx = dis[k=j]; vis[k] = ;
for(int j = head[k]; j!=-; j = edge[j].next)
if(!vis[edge[j].to])
dis[edge[j].to] = max(dis[edge[j].to], min(dis[k], edge[j].w) );
}
} int x[MAXN], y[MAXN];
int main()
{
int T;
scanf("%d", &T);
for(int kase = ; kase<=T; kase++)
{
scanf("%d%d", &n, &m);
init();
for(int i = ; i<=m; i++)
{
int u, v, w;
scanf("%d%d%d", &u, &v, &w);
addedge(u,v,w);
addedge(v,u,w);
} dijkstra();
printf("Scenario #%d:\n",kase);
printf("%d\n\n", dis[n]);
}
}
POJ1797 Heavy Transportation —— 最短路变形的更多相关文章
- POJ--1797 Heavy Transportation (最短路)
题目电波: POJ--1797 Heavy Transportation n点m条边, 求1到n最短边最大的路径的最短边长度 改进dijikstra,dist[i]数组保存源点到i点的最短边最大的路径 ...
- POJ 1797 Heavy Transportation 最短路变形(dijkstra算法)
题目:click here 题意: 有n个城市,m条道路,在每条道路上有一个承载量,现在要求从1到n城市最大承载量,而最大承载量就是从城市1到城市n所有通路上的最大承载量.分析: 其实这个求最大边可以 ...
- POJ-1797Heavy Transportation,最短路变形,用dijkstra稍加修改就可以了;
Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K Description Background Hugo ...
- (Dijkstra) POJ1797 Heavy Transportation
Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 53170 Accepted: ...
- POJ 1797 Heavy Transportation (Dijkstra变形)
F - Heavy Transportation Time Limit:3000MS Memory Limit:30000KB 64bit IO Format:%I64d & ...
- POJ 1797 Heavy Transportation (最短路)
Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 22440 Accepted: ...
- POJ1797 Heavy Transportation 【Dijkstra】
Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 21037 Accepted: ...
- poj1797 - Heavy Transportation(最大边,最短路变形spfa)
题目大意: 给你以T, 代表T组测试数据,一个n代表有n个点, 一个m代表有m条边, 每条边有三个参数,a,b,c表示从a到b的这条路上最大的承受重量是c, 让你找出一条线路,要求出在这条线路上的最小 ...
- [POJ1797] Heavy Transportation(最大生成树 || 最短路变形)
传送门 1.最大生成树 可以求出最大生成树,其中权值最小的边即为答案. 2.最短路 只需改变spfa里面的松弛操作就可以求出答案. ——代码 #include <queue> #inclu ...
随机推荐
- C 语言中的 feof()函数
功能: feof 是 C 语言标准库函数函数,其原型在 stdio.h 中,其功能是检测流上的文件结束符,如果文件结束,则返回非0值,否则返回0,文件结束符只能被 clearerr() 清除. 用法: ...
- day2之爬取拉勾网
认证流程 浏览器清空cookies 步骤一 访问拉勾网网站 https://www.lagou.com/ 做了些什么: 以get方式请求"https://www.lagou.com/&qu ...
- BZOJ 2973 入门OJ4798 石头游戏
矩阵递推 #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring ...
- 【BZOJ1412】狼和羊的故事(最小割)
题意:将一个由0,1,2构成的矩阵里的1与2全部分割最少需要选取多少条边 n,m<=100 思路:裸的最小割模型 相邻的格子连容量为1的边(其实可以少连很多遍,1与1,2与2之间的边是没有意义的 ...
- Laravel 中视图中使用PHP代码
{{ $name }}{{ date('Y-m-d H:i:s',time()) }}{{ in_array($name,$arr)?'true':'false' }} {{ isset($name) ...
- 使用注解开发springmvc
1.导入jar包 commons-logging-1.2.jar spring-aop-4.3.6.RELEASE.jar spring-beans-4.3.6.RELEASE.jar spring- ...
- Oracle外键级联删除和级联更新
https://www.2cto.com/database/201507/417496.html
- Linux 系统的常用命令之 rm ,rm -rf , rm -f 以及rm 命令的其他参数命令
1.rm -rf * 删除当前目录下的所有文件,这个命令很危险,应避免使用. 所删除的文件,一般都不能恢复! 2.rm -f 其中的,f参数 (f --force ) 忽略不存在的文件,不显示任何信息 ...
- [bzoj3709][PA2014]Bohater_贪心
bzoj-3709 PA-2014 Bohater 题目大意:在一款电脑游戏中,你需要打败n只怪物(从1到n编号).为了打败第i只怪物,你需要消耗d[i]点生命值,但怪物死后会掉落血药,使你恢复a[i ...
- mongDB的常用操作总结
目录 常用查询: 查询一条数据 查询子元素集合:image.id gte: 大于等于,lte小于等于... 查询字段不存在的数据not 查询数量: 常用更新 更新第一条数据的一个字段: 更新一条数据的 ...