OpenJudge 799:Heavy Transportation

总时间限制: 3000ms 内存限制: 65536kB

描述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.输入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.输出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.样例输入

1
3 3
1 2 3
1 3 4
2 3 5

样例输出

Scenario #1:
4
 #include<cstdio>
#include<algorithm>
using namespace std; int T,t,n,m;
int fa[]; struct node{
int u;
int v;
int w;
}edge[]; int cmp(node a,node b){
return a.w>b.w;
} int getfa(int x){
return fa[x]=fa[x]==x?x:getfa(fa[x]);
} int kruskal(){
int ans;
sort(edge+,edge+m+,cmp);
for(int i=;i<=n;++i)fa[i]=i;
for(int i=;i<=m;++i){
int U=getfa(edge[i].u);
int V=getfa(edge[i].v);
if(U!=V){
fa[U]=V;
ans=edge[i].w;
if(getfa()==getfa(n))return ans;//1---n连通即可不一定要走完整个树
}
}
} int main(){
scanf("%d",&T);
t=;
while(t<=T){
scanf("%d%d",&n,&m);
for(int i=;i<=m;++i)scanf("%d%d%d",&edge[i].u,&edge[i].v,&edge[i].w);
printf("Scenario #%d:\n%d\n\n",t,kruskal());
t++;
}
return ;
}

#图# #最大生成树# #kruskal# ----- OpenJudge 799:Heavy Transportation的更多相关文章

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

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

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

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

  3. POJ 1979 Heavy Transportation (kruskal)

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

  4. (最短路) Heavy Transportation --POJ--1797

    链接: http://poj.org/problem?id=1797 Heavy Transportation Time Limit: 3000MS   Memory Limit: 30000K To ...

  5. Heavy Transportation(最短路)

    poj 1797 ——Heavy Transportation 思路: 这道题我们可以采用类似于求最短路径的方法,用一种新的“松弛操作”去取代原本的方法. 我们可以记录d[u]为运送货物到点j时最大可 ...

  6. Heavy Transportation(最短路 + dp)

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

  7. POJ 1797 Heavy Transportation (Dijkstra变形)

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

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

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

  9. POJ 1797 Heavy Transportation

    题目链接:http://poj.org/problem?id=1797 Heavy Transportation Time Limit: 3000MS   Memory Limit: 30000K T ...

随机推荐

  1. 填写信息的文章区域text_area

    <!DOCTYPE html><html> <head> <meta charset="utf-8"> <title>& ...

  2. linux下的安装百度云网盘

    linux下的百度网盘 (2014-10-20 18:01:14) 标签: linux 百度网盘 网盘 百度 forlinux 分类: 技术博文 百度网盘说实话,其实我挺喜欢的,好处什么的,就不说了, ...

  3. PHP模板解析类实例

    作者:mckee 这篇文章主要介绍了PHP模板解析类,涉及php针对模板文件的解析与字符串处理的相关技巧,具有一定参考借鉴价值,需要的朋友可以参考下 <?php class template { ...

  4. Netbeans 6.8 + apktool_2.0.0b9 动态调试smali文件

    前言 很早就知道用Netbeans能够单步调试smali,一直拖到现在才真正的自己实现了一次~ 下面是详细步骤! 0×1 环境及工具 a.apktool_2.0.0b9 下载地址:http://con ...

  5. centos lvm常用命令

    # vgs -a  VG     #PV #LV #SN Attr   VSize  VFree  cinder   1   0   0 wz--n- 30.39g 30.39g  os       ...

  6. HDU 3265 Posters

    矩形面积并,一个拆成四个 #include<cstdio> #include<cstring> #include<cmath> #include<map> ...

  7. JQuery中的mouseover和mouseenter的区别

    mouseover和mouseout是一对:mouseenter和mouseleave是一对. 相同点:都是鼠标经过就触发事件 不同点: 给外盒子一个经过触发事件,但是mouseover会在鼠标经过外 ...

  8. DEDECMS整站复制

    1. 登录你的网站(织梦系统DedeCMS)后台,到“系统”–“系统设置”–“数据库备份/还原”,点击“数据备份选择”下面的“提交”: 2.拷贝备份的数据库文件到根目录/data/backupdata ...

  9. 使用PHPmailer 发送邮件,使用QQ smtp服务器

    <meta charset="utf-8"> <?php include("class.phpmailer.php"); include(&q ...

  10. Java出现“Error configuring application listener of class...”类似的错误解决

    错误如下: Error configuring application listener of class com.jsoft.jblog.listener.SessionListener java. ...