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. 读取cc2530节点的设备类型、协调器、路由器、终端。

    建立网络.加入网络流程分析 协调器节点:在1-10  实验8 网络通信实验2 组播通信中 while(MSGpkt) { switch(MSGpkt->hdr.event) { case ZDO ...

  2. 如何将CAD文件导入到Protel和PADS中

    一. 如何把CAD中的板框图纸导入到Protel中? a. 在CAD中单位设置为“毫米”,并做简单的处理,板框图是有合并还是分解都无所谓,另存为R12(*dxf)格式文件. b. 打开DXP,新建PC ...

  3. zepto学习之路--数组去重和原生reduce

    好吧开始读zepto的源代码,最前面给处理trim和reduce的原生实现,感觉写的很紧凑,其中reduce写的有点晦涩,个人感觉还不错.主要zepto的作者是无分号党,看起了有点不习惯. 3 if ...

  4. Linux的iptables常用配置范例(3)

    编辑/etc/rc.local,加入iptables -t nat -A POSTROUTING -s 192.168.0.0/24 -o eth1 -j MASQUERADE,外网口eth1为dhc ...

  5. avi格式详细介绍

    百度:http://wenku.baidu.com/link?url=KB7qKc6UG4aeU-i9FtXeV8Uou4JHPceiyz3HNbzCrQw4phY-qRlcp3tTSwYPeIgdx ...

  6. linux下 mysql 学习(一)

    1.登录mysql [root@test1 local]# mysql  Welcome to the MySQL monitor. Commands end with ; or g. Your My ...

  7. (中等) POJ 3660 Cow Contest,Floyd。

    Description N (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a programming con ...

  8. iOS ZBar扫码简单实现

    导入ZBarSDK文件并引入一下框架 AVFoundation.framework CoreMedia.framework CoreVideo.framework QuartzCore.framewo ...

  9. windows下查找指定端口被哪个程序占用

    在Windows环境下,用netstat命令查看某个端口号是否占用,为哪个进程所占用. eg.查看端口号为61078被哪个程序占用 1.查看端口号为61079被哪个PID所占用:Netstat –an ...

  10. Java 基础类型转换byte数组, byte数组转换基础类型

    Java 基础类型转换byte数组, byte数组转换基础类型 Java类型转换 java类对象转化为byte数组