(最短路) Heavy Transportation --POJ--1797
链接:
http://poj.org/problem?id=1797
Time Limit: 3000MS | Memory Limit: 30000K | |
Total Submissions: 25089 | Accepted: 6647 |
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
代码:
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std; #define N 1100
#define INF 0x3f3f3f3f3f int n, m, dist[N], G[N][N], v[N]; int DIST(int S, int E)
{
dist[]=;
v[]=; for(int i=; i<=n; i++)
dist[i] = G[][i]; for(int i=; i<=n; i++)
{
int index=-, MAX=-; for(int j=; j<=n; j++)
{
if(v[j]== && dist[j]>MAX)
{
index = j, MAX = dist[j];
}
}
v[index]=; for(int j=; j<=n; j++)
{
if(v[j]==)
{
int tmp = min(dist[index], G[index][j]);
if(tmp>dist[j])
dist[j]=tmp;
}
}
}
return dist[E];
} int main()
{
int t, k=; scanf("%d", &t); while(t--)
{
int a, b, w, i;
scanf("%d%d", &n, &m); memset(v, , sizeof(v));
memset(G, -, sizeof(G)); for(i=; i<=m; i++)
{
scanf("%d%d%d", &a, &b, &w);
G[a][b]=G[b][a]=max(G[a][b], w);
} int ans = DIST(, n); printf("Scenario #%d:\n", k++);
printf("%d\n\n", ans);
}
return ;
}
类似于 最大生成树
#include <iostream>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
using namespace std;
const int INF = (<<)-;
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
#define N 1100 int n, m, dist[N], G[N][N], vis[N]; int prim()
{
int i, j, ans = INF; for(i=; i<=n; i++)
dist[i] = G[][i];
dist[] = ; memset(vis, , sizeof(vis));
vis[] = ; for(i=; i<=n; i++)
{
int index = , Max = -;
for(j=; j<=n; j++)
{
if(!vis[j] && dist[j]>Max)
{
Max = dist[j];
index = j;
}
} if(index==) break; vis[index] = ; ans = min(ans, Max); if(index==n) return ans; ///当到达 n 点的时候结束 for(j=; j<=n; j++)
{
if(!vis[j] && dist[j]<G[index][j])
dist[j] = G[index][j];
}
} return ans;
} int main()
{
int t, iCase=;
scanf("%d", &t);
while(t--)
{
int i, u, v, x; scanf("%d%d", &n, &m); memset(G, -, sizeof(G)); for(i=; i<=m; i++)
{
scanf("%d%d%d", &u, &v, &x);
G[u][v] = G[v][u] = max(G[u][v], x);
} printf("Scenario #%d:\n%d\n\n", iCase++, prim());
}
return ;
}
(最短路) Heavy Transportation --POJ--1797的更多相关文章
- Heavy Transportation POJ 1797 最短路变形
Heavy Transportation POJ 1797 最短路变形 题意 原题链接 题意大体就是说在一个地图上,有n个城市,编号从1 2 3 ... n,m条路,每条路都有相应的承重能力,然后让你 ...
- Heavy Transportation POJ - 1797
题意 给你n个点,1为起点,n为终点,要求所有1到n所有路径中每条路径上最小值的最最值. 思路 不想打最短路 跑一边最大生成树,再扫一遍1到n的路径,取最小值即可,类似Frogger POJ - 22 ...
- kuangbin专题专题四 Heavy Transportation POJ - 1797
题目链接:https://vjudge.net/problem/POJ-1797 思路:请参考我列出的另一个题目,和这个题目要求的值相反,另一个清楚后,这个写的解释就明白了. 另一个类似题目的博客:h ...
- POJ 1797 ——Heavy Transportation——————【最短路、Dijkstra、最短边最大化】
Heavy Transportation Time Limit:3000MS Memory Limit:30000KB 64bit IO Format:%I64d & %I64 ...
- POJ 1797 Heavy Transportation(最大生成树/最短路变形)
传送门 Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 31882 Accept ...
- POJ 1797 Heavy Transportation (最短路)
Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 22440 Accepted: ...
- POJ 1797 Heavy Transportation (Dijkstra变形)
F - Heavy Transportation Time Limit:3000MS Memory Limit:30000KB 64bit IO Format:%I64d & ...
- POJ 1797 Heavy Transportation
题目链接:http://poj.org/problem?id=1797 Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K T ...
- poj 1797 Heavy Transportation(最大生成树)
poj 1797 Heavy Transportation Description Background Hugo Heavy is happy. After the breakdown of the ...
随机推荐
- ora-01652无法通过128(在temp表空间中)扩展temp段
有两种错误:1.数据表空间不足 2.临时表空间不足 有两种原因:一是临时表空间空间太小,二是不能自动扩展. 分析过程: 既然是temp表空间有问题,那当然就要从temp表空间说起啦.首先要说明的 ...
- Ansible playbooks
Playbook是Ansible的配置,部署和编排语言. 他们可以描述您希望远程系统执行的策略,或一般IT流程中的一组步骤. 如果Ansible modules是您workshop的工具,则playb ...
- mysql优化连接数
很多开发人员都会遇见”MySQL: ERROR 1040: Too many connections”的异常情况,造成这种情况的一种原因是访问量过高,MySQL服务器抗不住,这个时候就要考虑增加从服务 ...
- .net的内置对象
一 . 获取客户端,服务器端信息: Response.Write("客户端信息:"); Response.Write("<br>浏览器类型,版本:" ...
- CentOS 7安装Samba 4.6 版本步骤及错误解决方法
首先通过这次教训,让我养成一个好习惯:备份 备份 备份 不管做什么配置或者更改什么东西之前先做好备份! 还有我本身的一个坏毛病:眼高手低! 工厂有一台服务器,由以前的运维装的Samba ...
- Kendo UI 的弹框
弹出代码: "use strict"; (function (kendo) { kendo.messageShow = function (message, option) { v ...
- 一、消息队列之ActiveMQ的安装、配置和C#样例代码
最近有时间了,研究一下消息队列ActvieMQ,结合自己的实践和网上的一些大家内容,整理如下,所有步骤和链接均是正确的. 1.ActiveMQ ActiveMQ 是Apache出品,最流行的,能力强劲 ...
- Win10 激活
先看看你的WIN10激活状态:1.右键开始菜单2.运行3.slmgr.vbs -xpr KMS卸载方法:1.如果是KMSPico,则自带服务卸载批处理,2.不管是哪种KMS工具,卸载掉软件之后请执行以 ...
- geoserver 开发1
打开项目,会看见下面这些包(其实还有很多插件之类的包,我都删除了) 5)可以从Eclipse启动GeoServer了. 如果你已经安装了GeoServer,现在也可以打开它的登陆页面进行操作. 三 结 ...
- c++ tricks
1 关于virtual关键字的实验 1.1 在派生类中改变virtual函数访问权限 定义两个类A,B,其中B公有派生于A.A中定义一个private成员虚函数func,B中覆写此函数,但是将其访问权 ...