解题思路:典型的Kruskal,不能用floyed(会超时),上代码:

 #include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define inf 0x3f3f3f3f
const int maxn = ;
int father[maxn]; struct node{
int x, y, w;
}p[maxn*maxn]; //第一次开maxn,RE了一次 int cmp(node A, node B)
{
return A.w > B.w; //权值从大到小排序
} int Find(int x)
{
return father[x] == x ? x : father[x] = Find(father[x]);
} void Union(int x, int y)
{
int rootx = Find(x);
int rooty = Find(y);
if(rootx != rooty) father[rootx] = rooty;
return ;
} int main()
{
int t, n, m, kase = ;
scanf("%d", &t);
while(t--)
{
scanf("%d %d", &n, &m);
for(int i = ; i <= n; i++) father[i] = i;
for(int i = ; i <= m; i++)
scanf("%d %d %d", &p[i].x, &p[i].y, &p[i].w);
sort(p+, p++m, cmp); //注意这里是p+1开始 int ans = inf; //初始化ans为最大值
for(int i = ; i <= m; i++)
{
int rootx = Find(p[i].x);
int rooty = Find(p[i].y);
if(rootx != rooty)
{
Union(rootx, rooty);
//ans保存路径中最小的权值
if(p[i].w < ans) ans = p[i].w;
//如果1和n已经连接,则直接跳出
if(Find() == Find(n)) break;
}
}
//注意输出格式
printf("Scenario #%d:\n%d\n\n", kase++, ans);
}
return ;
}

POJ1797 Heavy Transportation的更多相关文章

  1. [poj1797]Heavy Transportation<最大生成树prim&kruskal>

    题目链接:http://poj.org/problem?id=1797 题意:给定n个点,m条边,每条边连接两点切有权值.求点1到点n的路径的上的最小边的值最大... 翻别人博客找到的题,方法挺多的, ...

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

    题目电波: POJ--1797 Heavy Transportation n点m条边, 求1到n最短边最大的路径的最短边长度 改进dijikstra,dist[i]数组保存源点到i点的最短边最大的路径 ...

  3. POJ1797 Heavy Transportation 【Dijkstra】

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

  4. (Dijkstra) POJ1797 Heavy Transportation

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

  5. POJ1797 Heavy Transportation —— 最短路变形

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

  6. [POJ1797] Heavy Transportation(最大生成树 || 最短路变形)

    传送门 1.最大生成树 可以求出最大生成树,其中权值最小的边即为答案. 2.最短路 只需改变spfa里面的松弛操作就可以求出答案. ——代码 #include <queue> #inclu ...

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

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

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

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

  9. POJ1797 Heavy Transportation (堆优化的Dijkstra变形)

    Background Hugo Heavy is happy. After the breakdown of the Cargolifter project he can now expand bus ...

随机推荐

  1. 执行用例,并生成报告——discover,HTMLRunner

    HTMLRunner需要下载Python3的格式,懒人链接:http://pan.baidu.com/s/1tp3Ts 参考:http://bbs.chinaunix.net/thread-41547 ...

  2. JS与Jquery 中的extend用法不同

    1, Jquery //jQuery 应用扩展   jQuery.extend({                  // 定义setApDiv     setApDiv:function () {  ...

  3. 《Pro Git》第1章 起步

    关于版本控制 什么是版本控制:记录文件内容变化,将来可查阅特定版本修订情况的系统. 版本控制演进 1)本地版本控制系统 2)集中化的版本控制系统(Centralized Version Control ...

  4. VC++6.0调试简单快捷键

    编译——F7 重新编译——Ctrl+F7 设置断点 ——F9 取消断点——F9 删除所有断点——Ctrl+Shift+F9 开始调试——F5 进行下一次调试——F5 停止调试——Shift+F5 逐过 ...

  5. 并发-HashMap和HashTable源码分析

    HashMap和HashTable源码分析 参考: https://blog.csdn.net/luanlouis/article/details/41576373 http://www.cnblog ...

  6. Gnostice PDFtoolkit VCL的安装

    Installation and Uninstallation For New Users Close all open applications including the IDE. Run the ...

  7. LeetCode—— Invert Binary Tree

    LeetCode-- Invert Binary Tree Question invert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9 to 4 / \ 7 2 ...

  8. js以excel为模板的打印

    使用excel为模板打印的好处是格式容易调整,这种方法要求客户端系统配置高度统一,譬如excel安装版本一致,存在服务器上的excel模板必须与客户端excel版本一致,而且不能用其他版本的excel ...

  9. hermite插值

    Hermite 插值就是要求插值函数不仅经过所给节点,而且要保证在该点的导数也相等.<备注:虽然还不理解这句话,但是还是先放这里!> 所谓样条曲线(Spline Curves)是指给定一组 ...

  10. AtCoder ARC097C Sorted and Sorted:dp

    传送门 题意 有 $ 2n $ 个球排成一行,其中恰好有 $ n $ 个白球和 $ n $ 个黑球.每个球上写着数字,其中白球上的数字的并集为 $ \lbrace 1 \dots n\rbrace $ ...