POJ 1791 Heavy Transportation(最大生成树)
来源:互联网 发布:千锋php视频教程 编辑:程序博客网 时间:2024/05/14 10:02
题面
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号节点的路径中,最短的边的最大值是多少。
直接求出最大生成树,输出即可。
#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<algorithm>using namespace std;#define MAX 1100#define MAXL MAX*MAXinline int read(){ int x=0,t=1;char ch=getchar(); while((ch<'0'||ch>'9')&&ch!='-')ch=getchar(); if(ch=='-'){t=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-48;ch=getchar();} return x*t;}struct Line{ int u,v,dis;}e[MAXL];int f[MAX],cnt=0,N,M;bool operator <(Line a,Line b){ return a.dis>b.dis;}int getf(int x){ return x==f[x]?x:f[x]=getf(f[x]);}void merge(int x,int y){ int a=getf(x); int b=getf(y); f[a]=b;}int main(){ int T=read(); for(int ttt=1;ttt<=T;++ttt) { N=read();M=read(); for(int i=1;i<=M;++i) e[i]=(Line){read(),read(),read()}; sort(&e[1],&e[M+1]); for(int i=1;i<=N;++i)f[i]=i; cnt=0; for(int i=1;i<N;++i) { int x,y; do {x=getf(e[++cnt].u),y=getf(e[cnt].v);} while(x==y); merge(x,y); if(getf(1)==getf(N)) { printf("Scenario #%d:\n%d\n\n",ttt,e[cnt].dis); break; } } }}
- POJ 1791 Heavy Transportation(最大生成树)
- poj 1797 Heavy transportation最大生成树
- POJ 1797 Heavy Transportation(最大生成树)
- poj 1797 Heavy Transportation(最大生成树)
- POJ - 1797 Heavy Transportation(求“最大生成树”)
- POJ 1797 Heavy Transportation(最大生成树-Prim)
- POJ 1797 Heavy Transportation(最大生成树)
- POJ 1797 Heavy Transportation(最大生成树)
- Heavy Transportation(最大生成树)
- poj 1797 Heavy Transportation 最小生成树 最大生成树
- POJ 1797 Heavy Transportation (Prime 最大生成树)
- POJ 1797 Heavy Transportation 【最大生成树,Prime】
- POJ1797 Heavy Transportation(最大生成树解)
- poj1797——Heavy Transportation(最大生成树)
- POJ1797-Heavy Transportation(Dijkstra 变式& 最大生成树)
- poj1797 Heavy Transportation 最大生成树
- POJ-1797Heavy Transportation (最小生成树问题)
- poj 1791 Heavy Transportation
- iOS tableView滑动卡顿的问题之一
- Android之xml解析和json解析
- 【线段树-区间更新求区间和】CDOJ 1057
- 《Java并发编程实战》笔记
- 尼姆博弈(Nimm Game)
- POJ 1791 Heavy Transportation(最大生成树)
- 【数据结构】中树的三种遍历方式详解
- hdu2033 人见人爱A+B(C语言)
- Solr 运维管理监控
- RH124-第十二节-网络管理
- String类中的compareTo方法总结
- PAT--1064. Complete Binary Search Tree
- 程序冲突及其解决
- Java之JVM逃逸分析