链接:

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. Ubuntu技巧之清理系统中无用的软件包

    如果你频繁的在你的系统中安装/卸载,那么不时的清理一下你的系统是十分必要的. 在Ubuntu终端中执行如下命令: sudo apt-get autoremove 屏幕输出是这个样子的: Reading ...

  2. 自定义worker的方法,及一例

    自定义的worker用于处理各种特殊需求. 有网友想用html_json提取雪球网(https://xueqiu.com/)的数据,可是雪球网用了反爬虫技术,网站要求有cookies才能访问到json ...

  3. java public project default private

  4. java多线程实例(2)

    public class ThreadDemo05 { public static void main(String args[]) { // 四个售票点应该控制同一个资源 Demo d = new ...

  5. 疯狂JAVA——第六章 面向对象(下)

    6.1包装类 java为了照顾程序员的传统习惯,所以提供了八种基本数据类型.但也带来不方便,例如所有引用类型都继承自Object类,都可当做Object类型变量使用.但基本数据类型的变量就不可以.如果 ...

  6. python文件的只读,只写操作

    只读:r rb(bytes类型数据) 只写:w wb(bytes类型数据) 在文件最后追加: f = open('log',mode='a',encoding='utf-8') f.write('这里 ...

  7. console.log等不能打印全部数据/信息

    有时候console.log在chrome调试控制台打印不全,如下: 这个时候,我们可以点击进去:用watch 工具,添加变量,右击copy value 选项:

  8. Mysql count(1) group_concat 高级用法(count 过滤条件,group_concat过滤条件)

    1.官方文档: count:COUNT(expr) [over_clause] https://dev.mysql.com/doc/refman/8.0/en/group-by-functions.h ...

  9. cmd 字符串截取

    @echo off set "url=www.mzwu.com" echo 1.字符串截取 echo %url:~4,4% echo %url:~4,-4% echo %url:~ ...

  10. 关于时间查询的sql语句

    今天 select * from 表名 where to_days(时间字段名) = to_days(now()); 昨天 SELECT * FROM 表名 WHERE TO_DAYS( NOW( ) ...