题意:

给出一个图,然后Q个询问,每次询问从一个节点到另一个节点,联通图中的“最大边和最小边之差”的最小值,但如果节点之间不连通,则输出-1.

思路:由于询问Q < 11,m < 1000,所以O(Q*n^2),Q*n^2 < 10^8,用最小生成树的思路,在给图上的边排好序的基础上,每次枚举最小边,然后做并查集枚举最大边,当查询的路径相通的时候,如果差值比上一次枚举最小边的差值小的时候,更新。

AC代码:

{CSDN:CODE:330547}
作者:u011652573 发表于2014-5-6 20:20:56 原文链接
阅读:47 评论:0 查看评论

[原]HDU-1598-find the most comfortable road(暴力枚举+Kruskal最小生成树)的更多相关文章

  1. HDU 1598 find the most comfortable road (罗列+Kruskal) 并检查集合

    Problem Description XX星有很多城市,城市之间通过一种奇怪的快速公路SARS(Super Air Roam Structure---超级空中漫游结构)进行交流.每条SARS都对行驶 ...

  2. HDU 1598 find the most comfortable road 并查集+贪心

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1598 find the most comfortable road Time Limit: 1000 ...

  3. hdu 1598 find the most comfortable road (并查集+枚举)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1598 find the most comfortable road Time Limit: 1000/ ...

  4. hdu 1598 find the most comfortable road(枚举+卡鲁斯卡尔最小生成树)

    find the most comfortable road Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ...

  5. hdu 1598 find the most comfortable road (并查集)

    find the most comfortable road Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ...

  6. HDU 1598 find the most comfortable road(最小生成树之Kruskal)

    题目链接: 传送门 find the most comfortable road Time Limit: 1000MS     Memory Limit: 32768 K Description XX ...

  7. HDU 1598 find the most comfortable road (MST)

    find the most comfortable road Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d ...

  8. hdu 1598 find the most comfortable road(并查集+枚举)

    find the most comfortable road Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ...

  9. HDU - 1598 find the most comfortable road 【最小生成树】

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1598 思路 用kruskal 算法 将边排序后 跑 kruskal 然后依次将最小边删除 再去跑 kr ...

随机推荐

  1. WCF基本概念

    WCF是基于Windows平台下开发和部署服务的SDK.服务是一组公开的功能集合. 面向服务(Service Orientatio,SO)是一组原则的抽象, 面向服务的应用程序(SOA)将众多服务聚集 ...

  2. IIS Express 一个网站配置多个 域名

      在配置localhost和IP都可以访问:   方法1: applicationhost.config文件配置: <bindings>   <binding protocol=& ...

  3. CNAME

    CNAME指别名记录也被称为规范名字.这种记录允许您将多个名字映射到同一台计算机. 通常用于同时提供WWW和MAIL服务的计算机.例如,有一台计算机名为“host.mydomain.com”(A记录) ...

  4. Keil中的code关键字

    一般说来,我们在C语言中定义的每一个变量初始化后都会占用一定的内存(RAM)空间.但是在keil中提供了一个特殊的关键字“code”,这个关键字在标准C中是没有的.其语法举例如下: unsigned ...

  5. Eclipse Plugin for Hadoop

    Eclipse 官网下载向导 下载 下载的安装文件放到~/setupEnv,将安装到/opt目录下 cd ~/setupEnv sudo tar zxvf eclipse-java-kepler-SR ...

  6. BZOJ2435: [Noi2011]道路修建

    这种水题真是……没一次AC都不好意思见人啊 P.S. LINUX无限栈真是爽炸了… 我爱递归 /**************************************************** ...

  7. spark分片个数的确定及Spark内存错误(GC error)的迂回解决方式

    我们知道,spark中每个分片都代表着一部分数据,那么分片数量如何被确认的呢? 首先我们使用最常见的HDFS+Spark,sparkDeploy的方式来讨论,spark读取HDFS数据使用的是spar ...

  8. 【leetcode】Multiply Strings(middle)

    Given two numbers represented as strings, return multiplication of the numbers as a string. Note: Th ...

  9. Unit4中的Annotation

    Unit4中的Annotation(注解.注释) JUnit4 使用 Java 5 中的注解(annotation),以下是JUnit4 常用的几个annotation介绍@Before:初始化方法@ ...

  10. iftop 使用

    测试中常常发现服务器网卡打满,那么这些流量具体占用情况如何呢? 这个时候我们要使用iftop来看看,首先我们要安装: 一. 安装 首先安装libpcap,下载链接:http://www.tcpdump ...