链接:

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. liblas 1.8.1编译安装

    liblas https://github.com/libLAS/libLAS/issues/102 https://liblas.org/start.html 源码 https://github.c ...

  2. Spoon新建repository的时候

    Spoon新建repository的时候,下面选项选择‘否’,不要选择‘是’,不然可能会出错.

  3. mysql 存储过程分页 转载

    /* --名称:MYSQL版查询分页存储过程 by peace 2013-8-14 --输入参数:@fields -- 要查询的字段用逗号隔开 --输入参数:@tables -- 要查询的表 --输入 ...

  4. Process子类

    创建新的进程还能够使用类的方式,可以自定义一个类,继承Process类,每次实例化这个类的时候,就等同于实例化一个进程对象,请看下面的实例: from multiprocessing import P ...

  5. pycharm 远程开发

    1. 服务器安装图形化 和 pycharm 本地使用 MobaXterm 工具登陆 session配置 勾选 x11-forwarding 运行pycharm.sh 2. 本地pycharm 远程服务 ...

  6. Ansible Playbook 循环

    Standard Loops 为了节省一些打字,重复的任务可以写成如下: - name: add several users user: name: "{{ item }}" st ...

  7. 大型运输行业实战_day04_2_高级查询

    1.高级查询最总效果 2.高级查询步骤 2.1页面输入框显示 开始车站:<input id="startStation" type="text" valu ...

  8. 检测到有潜在危险的 Request.Form 值——ValidateRequest的使用

    1.aspx中 在 Web 应用程序中,要阻止依赖于恶意输入字符串的黑客攻击,约束和验证用户输入是必不可少的.跨站点脚本攻击就是此类攻击的一个示例. 当请求验证检测到潜在的恶意客户端输入时,会引发此异 ...

  9. javascript基础代码

    1.点击改变HTML内容 <html> <head> <meta charset="UTF-8"> <script> functio ...

  10. 91. Decode Ways (Array; DP)

    A message containing letters from A-Z is being encoded to numbers using the following mapping: 'A' - ...