链接:

http://poj.org/problem?id=1797

Heavy Transportation
Time Limit: 3000MS   Memory Limit: 30000K
Total Submissions: 25089   Accepted: 6647

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

代码:

#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的更多相关文章

  1. Heavy Transportation POJ 1797 最短路变形

    Heavy Transportation POJ 1797 最短路变形 题意 原题链接 题意大体就是说在一个地图上,有n个城市,编号从1 2 3 ... n,m条路,每条路都有相应的承重能力,然后让你 ...

  2. Heavy Transportation POJ - 1797

    题意 给你n个点,1为起点,n为终点,要求所有1到n所有路径中每条路径上最小值的最最值. 思路 不想打最短路 跑一边最大生成树,再扫一遍1到n的路径,取最小值即可,类似Frogger POJ - 22 ...

  3. kuangbin专题专题四 Heavy Transportation POJ - 1797

    题目链接:https://vjudge.net/problem/POJ-1797 思路:请参考我列出的另一个题目,和这个题目要求的值相反,另一个清楚后,这个写的解释就明白了. 另一个类似题目的博客:h ...

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

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

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

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

  6. POJ 1797 Heavy Transportation (最短路)

    Heavy Transportation Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 22440   Accepted:  ...

  7. POJ 1797 Heavy Transportation (Dijkstra变形)

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

  8. POJ 1797 Heavy Transportation

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

  9. poj 1797 Heavy Transportation(最大生成树)

    poj 1797 Heavy Transportation Description Background Hugo Heavy is happy. After the breakdown of the ...

随机推荐

  1. sysbench相关

    Sysbench工具是集系统测试和数据库测试一体的测试工具,但是传统的sysbench在数据库测试方面,没有遵循TPC-C测试模型,仅仅支持单个表的数据.而在实际的业务场景中,业务逻辑复杂的多.开源的 ...

  2. JAVA中会存在内存泄露吗

    所谓内存泄露就是指一个不再被程序使用的对象或变量一直被占据在内存中.java中有垃圾回收机制,它可以保证一对象不再被引用的时候,即对象编程了孤儿的时候,对象将自动被垃圾回收器从内存中清除掉.由于Jav ...

  3. ArcGIS模型构建器案例学习-批量删除空要素类地理模型

    ArcGIS模型构建器案例学习笔记-批量删除空要素类地理模型 联系方式:谢老师,135-4855-4328,xiexiaokui@qq.com 目的:批量删除记录个数为0的矢量文件 优点:逻辑清晰,不 ...

  4. Numpy数据存取

    Numpy数据存取 numpy提供了便捷的内部文件存取,将数据存为np专用的npy(二进制格式)或npz(压缩打包格式)格式 npy格式以二进制存储数据的,在二进制文件第一行以文本形式保存了数据的元信 ...

  5. 使用git提交代码到GitHub

    0.下载Git Bash,在Windows系统可以用Git Bash通过简单的命令将代码提交到GitHub1.打开项目所在的文件夹,右键,"Git Bash Here"2.初次使用 ...

  6. suse11 sp4(虚拟机) 安装程序时报错 找不到iso

    一个可能原因是iso掉了.我用的virtualbox安装的suse,支持不是很好,suse启动后,因为驱动问题强制umount了iso,所以掉了.重启后,不要去动virtualbox插件问题,插件错误 ...

  7. 取消svn add

    svn commit之前,add的东西都可以取消. 通过先执行svn cleanup,再执行svn revert --recursive example_folder.

  8. 52. N-Queens II (Array; Back-Track)

    Follow up for N-Queens problem. Now, instead outputting board configurations, return the total numbe ...

  9. 【校招面试 之 C/C++】第17题 C 中的malloc相关

    1.malloc (1)原型:extern void *malloc(unsigned int num_bytes); 头文件:#include <malloc.h> 或 #include ...

  10. mysql的外键知识

    外键的作用 1.用来约束两张表中的字段 2.外键也可以用来实现一对多 我们先举一个这样的例子,让大家对外键有一个基本的认识 当前我们有一个需求就是,需要创建一张表,这张表要包括“姓名”,“年龄”,“工 ...