(最短路) 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 ...
随机推荐
- Object-c中的单例
#import <UIKit/UIKit.h> @interface UniAudioPlayer:NSObject{ } +(UniAudioPlayer*) getInstance; ...
- log4j显示hibernate sql参数的配置
#下面的两条配置非常重要,设置为trace后,将可以看到打印出sql中 ? 占位符的实际内容 #this is the most important config for showing parame ...
- Activity生命周期,Activity传值(Intent)
生命周期: 从出生到死亡 Activity生命周期的7个方法和3个循环 onCreate() 创建时调用onRestart() 不可见到可见时调用onStart() 用户可见时调用onResume() ...
- Intellij IDEA Debug
Debug用来追踪代码的运行流程,通常在程序运行过程中出现异常,启用Debug模式可以分析定位异常发生的位置,以及在运行过程中参数的变化.通常我们也可以启用Debug模式来跟踪代码的运行流程去学习三方 ...
- Linux查看内存使用情况
输入:top PID:进程的ID USER:进程所有 PR:进程的优先级别,越小越优先被执 NInice: VIRT:进程占用的虚拟内 RES:进程占用的物理内 SHR:进程使用的共享内 S:进程的状 ...
- WebDriverException:Element is not clickable at point - selenium执行过程中遇到的相关报错
Element is not clickable at point (x, y) 这段可以忽略:本文来自 https://www.cnblogs.com/lozz/p/9947430.html 引起这 ...
- 爬楼梯 · Climbing Stairs
[抄题]: 假设你正在爬楼梯,需要n步你才能到达顶部.但每次你只能爬一步或者两步,你能有多少种不同的方法爬到楼顶部? [思维问题]: 不知道一步.两步怎么加.还是用iteration迭代.此题公式可被 ...
- c语言定义函数指针和typedef简写
二种方法来定义函数指针 #include<stdio.h> #include<stdlib.h> #include<Windows.h> int add(int a ...
- catkin-tools
http://catkin-tools.readthedocs.io/en/latest/cheat_sheet.html 一.Initializing Workspaces初始化工作空间 初始化具有 ...
- ROS两种workspace :overlay rosbuild_ws->catkin_ws->ROS库,
概念 ROS里面有一系列概念,作为初学者,最先接触的概念无非是node, package和workspace. node node是ROS里面最小的执行单位,你可以把node看成是一个main函数,当 ...