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
#include<cstdio>
#include<string>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<cstring>
#include<set>
#include<queue>
#include<algorithm>
#include<vector>
#include<map>
#include<cctype>
#include<stack>
#include<sstream>
#include<list>
#include<assert.h>
#include<bitset>
#include<numeric>
#define debug() puts("++++")
#define gcd(a,b) __gcd(a,b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define fi first
#define se second
#define pb push_back
#define sqr(x) ((x)*(x))
#define ms(a,b) memset(a,b,sizeof(a))
#define sz size()
#define be begin()
#define mp make_pair
#define pu push_up
#define pd push_down
#define cl clear()
#define lowbit(x) -x&x
#define all 1,n,1
#define rep(i,x,n) for(int i=(x); i<=(n); i++)
#define in freopen("in.in","r",stdin)
#define out freopen("out.out","w",stdout)
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;
const int INF = 0x3f3f3f3f;
const LL LNF = 1e18;
const int maxn = +;
const int maxm = 1e6 + ;
const double PI = acos(-1.0);
const double eps = 1e-;
const int dx[] = {-,,,,,,-,-};
const int dy[] = {,,,-,,-,,-};
int dir[][] = {{,},{,-},{-,},{,}};
const int mon[] = {, , , , , , , , , , , , };
const int monn[] = {, , , , , , , , , , , , };
int dp[][],dis[maxn];
int t,n,m,u,v,w;
int x[maxn],y[maxn],vis[maxn];
int ca;
void dij()
{
ms(vis,);
rep(i,,n) dis[i]=dp[][i];
dis[]=;
vis[]=;
for(int i=;i<n;i++) //
{
int Max=,k=;
rep(j,,n)
if(!vis[j] && dis[j]>Max)
Max=dis[k=j];
vis[k]=;
rep(j,,n)
if(!vis[j] && dis[j]<min(dis[k], dp[k][j]))
dis[j]=min(dis[k],dp[k][j]);
}
}
int main()
{
ca=;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
ms(vis,);
ms(dp,);
while(m--)
{
scanf("%d%d%d",&u,&v,&w);
dp[u][v]=dp[v][u]=w;
}
dij();
printf("Scenario #%d:\n%d\n\n",ca++,dis[n]);
}
}

dij

#include<cstdio>
#include<string>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<cstring>
#include<set>
#include<queue>
#include<algorithm>
#include<vector>
#include<map>
#include<cctype>
#include<stack>
#include<sstream>
#include<list>
#include<assert.h>
#include<bitset>
#include<numeric>
#define debug() puts("++++")
#define gcd(a,b) __gcd(a,b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define fi first
#define se second
#define pb push_back
#define sqr(x) ((x)*(x))
#define ms(a,b) memset(a,b,sizeof(a))
#define sz size()
#define be begin()
#define mp make_pair
#define pu push_up
#define pd push_down
#define cl clear()
#define lowbit(x) -x&x
#define all 1,n,1
#define rep(i,x,n) for(int i=(x); i<=(n); i++)
#define in freopen("in.in","r",stdin)
#define out freopen("out.out","w",stdout)
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;
const int INF = 0x3f3f3f3f;
const LL LNF = 1e18;
const int maxn = 1e5+;
const int maxm = 1e6 + ;
const double PI = acos(-1.0);
const double eps = 1e-;
const int dx[] = {-,,,,,,-,-};
const int dy[] = {,,,-,,-,,-};
int dir[][] = {{,},{,-},{-,},{,}};
const int mon[] = {, , , , , , , , , , , , };
const int monn[] = {, , , , , , , , , , , , };
int fa[maxn],dis[maxn];
int t,n,m,u,v,w;
int vis[maxn];
int ca;
struct node
{
int u,v,w;
bool operator < (const node &x) const{
return w>x.w;
}
}e[maxn<<];
int Find(int x)
{
return x==fa[x]?x:Find(fa[x]);
} int main()
{
ca=;
scanf("%d",&t);
while(t--)
{
int ans=INF;
scanf("%d%d",&n,&m);
rep(i,,n) fa[i]=i;
rep(i,,m)
{
scanf("%d%d%d",&e[i].u,&e[i].v,&e[i].w);
}
sort(e+,e+m+);
rep(i,,m)
{
int fx=Find(e[i].u);
int fy=Find(e[i].v);
if(Find()!=Find(n)) //源汇点不在同一连通分量就一直加边
{
ans=e[i].w;
fa[fx]=fy;
}
else break; //起点和终点一旦连通那么解就是这条边了
}
printf("Scenario #%d:\n%d\n\n",ca++,ans);
}
}

kruskal

POJ 1797 Heavy Transportation 【最大生成树的最小边/最小瓶颈树】的更多相关文章

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

    题目链接:POJ 1797 Description Background Hugo Heavy is happy. After the breakdown of the Cargolifter pro ...

  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 / SCU 1819 Heavy Transportation (图论,最短路径)

    POJ 1797 Heavy Transportation / SCU 1819 Heavy Transportation (图论,最短路径) Description Background Hugo ...

  4. POJ.1797 Heavy Transportation (Dijkstra变形)

    POJ.1797 Heavy Transportation (Dijkstra变形) 题意分析 给出n个点,m条边的城市网络,其中 x y d 代表由x到y(或由y到x)的公路所能承受的最大重量为d, ...

  5. POJ 1797 Heavy Transportation

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

  6. POJ 1797 Heavy Transportation SPFA变形

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

  7. POJ 1797 Heavy Transportation(Kruskal灵活使用)(瓶颈树)

    题意: 求1到n路径上最大的最小值. 原因:样例输入 1 3 3 1 2 3 1 3 4 2 3 5 1-2最多可以运输3,2-3可最多以运输5,但是2的来源只有3,所以路径1-2-3上能运输的量为3 ...

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

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

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

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

  10. POJ 1797 Heavy Transportation (Dijkstra变形)

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

随机推荐

  1. Proxmap Sort

    这个排序是桶排序和基数排序的改进,理解了前两者,这个排序很容易理解 先回忆下桶排序是怎么回事,它与桶的区别在于入桶规则,桶排序里是1入1号桶,2入2号桶 这个排序把数字分区了,然后给出一个所谓的键,例 ...

  2. JAVA获取Classpath根路径的方法

    方法一: String path = Test.class.getResource("/").toString(); System.out.println("path = ...

  3. 20155335《java程序设计》第一周学习总结

    18个章节的问题 (1)为什么需要JVM让java跨平台? (2)JVM与JDK,与JRE的关系? (3)为什么 -0/3 结果是 0,而 -0.0/3.0 结果是 -0.0?(注意后边的结果0带负号 ...

  4. python keras YOLOv3实现目标检测

    1.连接 https://www.jianshu.com/p/3943be47fe84

  5. js 重置表单

    //方法一document.getElementById("myform").reset(); //方法二 ].reset(); //方法三 使用input按钮 <input ...

  6. apache log 按日期记录 格式 <GOOD>-- (转)

    在apache的配置文件中找到ErrorLog logs/error_logCustomLog logs/access_log common Linux系统配置方法: 将其改为ErrorLog “| ...

  7. python 实现二叉树相关算法

    一.构建与遍历二叉树 基本性质 1)在二叉树的第i层上最多有2i-1 个节点 .(i>=1)2)二叉树中如果深度为k,那么最多有2k-1个节点.(k>=1)3)在完全二叉树中,具有n个节点 ...

  8. Bagging和Boosting 概念及区别(转)

    Bagging和Boosting都是将已有的分类或回归算法通过一定方式组合起来,形成一个性能更加强大的分类器,更准确的说这是一种分类算法的组装方法.即将弱分类器组装成强分类器的方法. 首先介绍Boot ...

  9. response.getWriter().write()和 response.getWriter().print()的区别

    异步上传图片的代码.发现里面用了response.getWriter().print(),故联想到response.getWriter().writer(),经过一番api的查找与实操,总结如下: r ...

  10. setsockopt 详解

    1. closesocket(一般不会立即关闭而经历TIME_WAIT的过程)后想继续重用该socket: BOOL bReuseaddr=TRUE; setsockopt(s,SOL_SOCKET  ...