Heavy Transportation
Time Limit: 3000MS   Memory Limit: 30000K
Total Submissions:46898   Accepted: 12204

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 题意:
有一个什么东西要运到什么地方去,可是不知道道路有没有这么大的承载力,所以问从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)的更多相关文章

  1. POJ 1797 Heavy Transportation(Dijkstra)

    http://poj.org/problem?id=1797 题意 :给出N个城市M条边,每条边都有容量值,求一条运输路线使城市1到N的运输量最大. 思路 :用dijkstra对松弛条件进行变形.解释 ...

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

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

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

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

  4. POJ 1797 Heavy Transportation (Dijkstra变形)

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

  5. poj 1797 Heavy Transportation(最短路径Dijkdtra)

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

  6. POJ 1797 Heavy Transportation (dijkstra 最小边最大)

    Heavy Transportation 题目链接: http://acm.hust.edu.cn/vjudge/contest/66569#problem/A Description Backgro ...

  7. POJ 1797 Heavy Transportation(Dijkstra变形——最长路径最小权值)

    题目链接: http://poj.org/problem?id=1797 Background Hugo Heavy is happy. After the breakdown of the Carg ...

  8. poj 1797 Heavy Transportation(Dijkstar变形)

    http://poj.org/problem?id=1797 给定n个点,及m条边的最大负载,求顶点1到顶点n的最大载重量. 用Dijkstra算法解之,只是需要把“最短路”的定义稍微改变一下, A到 ...

  9. poj 1797 Heavy Transportation(最短路变种2,连通图的最小边)

    题目 改动见下,请自行画图理解 具体细节也请看下面的代码: 这个花了300多ms #define _CRT_SECURE_NO_WARNINGS #include<string.h> #i ...

随机推荐

  1. python排序 sorted()与list.sort() (转)

    该文章为转载:原文地址为:https://www.cnblogs.com/zuizui1204/p/6422939.html 只要是可迭代对象都可以用sorted . sorted(itrearble ...

  2. vim的几个常用操作

    现在很少会有人用vim来写代码,所以vim更常用在server上面编辑配置文件或者少量代码编辑: vim操作命令非常之多,如果仅用作一个配置文件的编辑器,掌握几个常用的操作就够了: 常用的操作其实就是 ...

  3. java开发支付宝支付详细流程_demo的运行

    首先我要吐槽一下支付宝的开放平台简直就是一个迷宫,赞同的顶一下,下面我把要下载的地址给贴出来要不真不好找: 一.准备工作 1.签名工具下载 https://docs.open.alipay.com/2 ...

  4. maven项目 报错 org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):

    ssm的项目如果在mapper.xml  mapper接口 配置没问题的情况下  项目依然报org.apache.ibatis.binding.BindingException: Invalid bo ...

  5. Nginx 针对上游服务器缓存

    L:99 nginx缓存 : 定义存放缓存的载体 proxy_cache 指令 Syntax: proxy_cache zone | off; Default: proxy_cache off; Co ...

  6. 法语Linux NuTyX 11 RC2 发布

    读 NuTyX是一个法语Linux发行版(具有多语言支持),由Linux From Scratch和Beyond Linux From Scratch构建,带有一个名为“cards”的自定义包管理器. ...

  7. Maven使用(一)—— Maven的安装与全局配置

    一.Maven安装 Maven的安装步骤: 1.Maven官网(http://maven.apache.org/)下载压缩包,解压缩,当前最新版本是apache-maven-3.5.3-bin.zip ...

  8. UOJ275 [清华集训2016] 组合数问题 【Lucas定理】【数位DP】

    题目分析: 我记得很久以前有人跟我说NOIP2016的题目出了加强版在清华集训中,但这似乎是一道无关的题目? 由于$k$为素数,那么$lucas$定理就可以搬上台面了. 注意到$\binom{i}{j ...

  9. 一个模拟——抢票部分功能的 简单版(主要实例化一下 Lock 的使用)

    """ 抢票! 多个用户在同时读写同一个数据 """ from multiprocessing import Process,Lock im ...

  10. Matplotlib学习---用matplotlib画阶梯图(step plot)

    这里利用Nathan Yau所著的<鲜活的数据:数据可视化指南>一书中的数据,学习画图. 数据地址:http://datasets.flowingdata.com/us-postage.c ...