poj 1797 Heavy Transportation

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.

Sample Input

1

3 3

1 2 3

1 3 4

2 3 5

Sample Output

Scenario #1:

4

题目大意:给出一张图,求从1到n的路径上权值的最大的最小值。

解题思路:最大生成树。用Prim算法,改动一些地方即可了。

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cstdlib>
using namespace std; typedef long long ll;
const int N = 1005;
const int INF = 0x3f3f3f3f;
int n, m;
int D[N][N], dis[N], vis[N], ans; void init() {
ans = INF;
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= n; j++) {
D[i][j] = 0;
}
}
for (int i = 0; i <= n; i++) dis[i] = 0;
for (int i = 0; i <= n; i++) vis[i] = 0;
} void input() {
scanf("%d%d", &n, &m);
int a, b, len;
for (int i = 0; i < m; i++) {
scanf("%d %d %d", &a, &b, &len);
D[a][b] = D[b][a] = len;
}
} void Prim() {
int k;
for (int i = 1; i <= n; i++) {
dis[i] = D[1][i];
}
vis[1] = 1;
for (int i = 0; i < n - 1; i++) {
int L = -2;
for (int j = 1; j <= n; j++) {
if (!vis[j] && dis[j] > L) {
L = dis[j];
k = j;
}
}
if (ans > L) ans = L;
if (k == n) break;
vis[k] = 1;
for (int j = 1; j <= n; j++) {
if (!vis[j] && D[j][k] > dis[j]) {
dis[j] = D[j][k];
}
}
}
printf("%d\n\n", ans);
} int main() {
int T, Case = 1;
scanf("%d", &T);
while (T--) {
printf("Scenario #%d:\n", Case++);
init();
input();
Prim();
}
return 0;
}

poj 1797 Heavy Transportation(最大生成树)的更多相关文章

  1. POJ 1797 Heavy Transportation (最大生成树)

    题目链接:POJ 1797 Description Background Hugo Heavy is happy. After the breakdown of the Cargolifter pro ...

  2. POJ 1797 Heavy Transportation / SCU 1819 Heavy Transportation (图论,最短路径)

    POJ 1797 Heavy Transportation / SCU 1819 Heavy Transportation (图论,最短路径) Description Background Hugo ...

  3. POJ.1797 Heavy Transportation (Dijkstra变形)

    POJ.1797 Heavy Transportation (Dijkstra变形) 题意分析 给出n个点,m条边的城市网络,其中 x y d 代表由x到y(或由y到x)的公路所能承受的最大重量为d, ...

  4. POJ 1797 Heavy Transportation

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

  5. POJ 1797 Heavy Transportation SPFA变形

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

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

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

  7. POJ 1797 Heavy Transportation (Dijkstra变形)

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

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

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

  9. POJ 1797 Heavy Transportation (Dijkstra)

    题目链接:POJ 1797 Description Background Hugo Heavy is happy. After the breakdown of the Cargolifter pro ...

随机推荐

  1. 全国DNS服务器地址(部分)

    广东: 广东省广州市(中国电信) 首选DNS:61.144.56.100 备份DNS:61.144.56.101 广东省广州市越秀区(中国电信) 首选DNS:202.96.128.86 备份DNS:2 ...

  2. 常用的Python代码段

    过滤列表 #filter out empty strings in a sting list list = [x for x in list if x.strip()!=''] 一行一行地读文件 wi ...

  3. Varnish 实战项目

    实现基于Keepalived+Haproxy+Varnish+LNMP企业级架构 原理:缓存,又称加速器,用于加速运行速度较快的设备与较慢设备之间的通信.基于程序的运行具有局部性特征其能实现加速的功能 ...

  4. Velocity(5)——#macro 指令

    1 #macro(formatIncreaseData $increase) 2 #if(${product.onlineStatusFlag} =='0') 3 -- 4 #elseif(!$inc ...

  5. 用python模拟登录(解析cookie + 解析html + 表单提交 + 验证码识别 + excel读写 + 发送邮件)

    老婆大人每个月都要上一个网站上去查数据,然后做报表. 为了减轻老婆大人的工作压力,所以我决定做个小程序,减轻我老婆的工作量. 准备工作 1.tesseract-ocr 这个工具用来识别验证码,非常好用 ...

  6. scala(一)Nothing、Null、Unit、None 、null 、Nil理解

    相对于java的类型系统,scala无疑要复杂的多!也正是这复杂多变的类型系统才让OOP和FP完美的融合在了一起! Nothing: 如果直接在scala-library中搜索Nothing的话是找不 ...

  7. Chrome 浏览器报 filed to load resource:net err cache read failure 错误:

    在IE/FF下没有该错误提示,但在Chrome下命令行出现如下错误信息: Failed to load resource: net::ERR_CACHE_MISS 该问题是Chrome浏览器开发工具的 ...

  8. AIO5系统中关于赠品处理的方法

    最近频繁有人问我,关于赠品在AIO5系统中如何处理.首先AIO5系统支持赠品处理关于赠品,在AIO5系统中走的是[其他出库单]路径:仓库--仓库作业--其他出库单--新增(如下图) 通常赠品对应的业务 ...

  9. html5开发学习 html5自学需要怎么学

    记得很多大鳄都说过一句话:只要站在风口上,猪都能飞起来.而对于如今的IT技术领域来说,无疑这只幸运的"猪"非html5莫属.html5开发技术在16年迎来了一个飞跃的发展,这也让很 ...

  10. Mybatis(二)参数(Parameters)传递

    Mybatis参数(Parameters)传递  1..单个参数 可以接受基本类型,对象类型,集合类型的值.这种情况MyBatis可直接使用这个参数,不需要经过任何处理. <!-- 根据id查询 ...