POJ 1979 Heavy Transportation (kruskal)
| Time Limit: 3000MS | Memory Limit: 30000K | |
| Total Submissions:46898 | Accepted: 12204 |
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 题意:
有一个什么东西要运到什么地方去,可是不知道道路有没有这么大的承载力,所以问从1到n路径的最小值中的最大值是多少。
思路
用kruskal建树,知道1和n在一个集合中为止。
代码
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
struct node
{
int x,y,dis;
}e[];
int f[];
int n,m; bool cmp(node x,node y)
{
return x.dis>y.dis;
} int getf(int t)
{
if(f[t]==t){
return t;
}
return f[t]=getf(f[t]);
} void Merge(int x,int y)
{
int t1=getf(x);
int t2=getf(y);
if(t1!=t2){
f[t2]=t1;
}
} bool jud(int x,int y)
{
int t1=getf(x);
int t2=getf(y);
if(t1==t2){return true;}
else return false;
} int kruskal()
{
sort(e+,e+m+,cmp);
for(int i=;i<=n;i++){
f[i]=i;
}
for(int i=;i<=m;i++){
Merge(e[i].x,e[i].y);
if(jud(,n)){return e[i].dis;}
}
return ; } int main()
{
int T;
int y=;
scanf("%d",&T);
while(T--){
y++;
scanf("%d%d",&n,&m);
for(int i=;i<=m;i++){
scanf("%d%d%d",&e[i].x,&e[i].y,&e[i].dis);
}
printf("Scenario #%d:\n%d\n\n",y,kruskal());
}
}
POJ 1979 Heavy Transportation (kruskal)的更多相关文章
- POJ 1797 Heavy Transportation(Dijkstra)
http://poj.org/problem?id=1797 题意 :给出N个城市M条边,每条边都有容量值,求一条运输路线使城市1到N的运输量最大. 思路 :用dijkstra对松弛条件进行变形.解释 ...
- poj 1797 Heavy Transportation(最大生成树)
poj 1797 Heavy Transportation Description Background Hugo Heavy is happy. After the breakdown of the ...
- POJ 1797 Heavy Transportation(最大生成树/最短路变形)
传送门 Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 31882 Accept ...
- POJ 1797 Heavy Transportation (Dijkstra变形)
F - Heavy Transportation Time Limit:3000MS Memory Limit:30000KB 64bit IO Format:%I64d & ...
- poj 1797 Heavy Transportation(最短路径Dijkdtra)
Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 26968 Accepted: ...
- POJ 1797 Heavy Transportation (dijkstra 最小边最大)
Heavy Transportation 题目链接: http://acm.hust.edu.cn/vjudge/contest/66569#problem/A Description Backgro ...
- POJ 1797 Heavy Transportation(Dijkstra变形——最长路径最小权值)
题目链接: http://poj.org/problem?id=1797 Background Hugo Heavy is happy. After the breakdown of the Carg ...
- poj 1797 Heavy Transportation(Dijkstar变形)
http://poj.org/problem?id=1797 给定n个点,及m条边的最大负载,求顶点1到顶点n的最大载重量. 用Dijkstra算法解之,只是需要把“最短路”的定义稍微改变一下, A到 ...
- poj 1797 Heavy Transportation(最短路变种2,连通图的最小边)
题目 改动见下,请自行画图理解 具体细节也请看下面的代码: 这个花了300多ms #define _CRT_SECURE_NO_WARNINGS #include<string.h> #i ...
随机推荐
- linux下更改MySQL数据库存储路径
参考地址:1.https://blog.csdn.net/ArnoBM/article/details/83008212 2.http://www.cnblogs.com/lyongde/p/3725 ...
- How to install Lion on PC
open 'InstallESD.dmg' open '/Volumes/Mac OS X Install ESD/BaseSystem.dmg' rm '/Volumes/Mac OS X Base ...
- Tunnel Warfare(线段树取连续区间)
emmmmmmmm我菜爆了 思路来自:https://blog.csdn.net/chudongfang2015/article/details/52133243 线段树最难的应该就是要维护什么东西 ...
- VS Code 编辑器
使用VS Code 编辑器有一段时间了,感觉非常好用,已经成为了我的第一选择了.现在需要学习了一下了. 1,更改编辑器的默认设置 文件 =>首选项 => 设置 或 ctrl + ,(逗号) ...
- 前端部分-CSS基础介绍
CSS介绍 CSS(Cascading Style Sheet,层叠样式表)定义如何显示HTML元素.也就是定义相应的标签语言来定制显示样式达到一定的显示效果. 每个CSS样式由两个组成部分:选择器和 ...
- windows 环境下通过运行快速启动程序
在windows环境下,我们可以使用一些系统内置的快捷键来快速启动我们想要的应用程序,我这里举例几个我经常使用的,比如: 快捷键 功能说明 services.msc 查看系统服务 gpedit.ms ...
- MT【249】离心率两题
椭圆$\dfrac{x^2}{a^2}+\dfrac{y^2}{b^2}=1,(a>b>0)$的一个焦点为$F$,过$F$的直线交椭圆于$A,B$两点,$M$是点$A$关于原点的对称点.若 ...
- 【agc030f】Permutation and Minimum(动态规划)
[agc030f]Permutation and Minimum(动态规划) 题面 atcoder 给定一个长度为\(2n\)的残缺的排列\(A\),定义\(b_i=min\{A_{2i-1},A_{ ...
- Codeforces | CF1033D 【Divisors】
题目大意:给定\(n(1\leq n\leq500)\)个数\(a_1,a_2\cdots,a_n(1\leq a_i\leq2\cdot10^{18})\),每个数有\(3\sim5\)个因数,求\ ...
- css border制作小三角形状及气泡框(兼容IE6)
先看下CSS盒模型 一个盒子包括: margin+border+padding+content 上下左右边框交界处出呈现平滑的斜线. 利用这个特点, 通过设置不同的上下左右边框宽度或者颜色可以得到小三 ...