One day, Tom traveled to a country named BGM. BGM is a small country, but there are N (N <= 100) towns in it. Each town products one kind of food, the food will be transported to all the towns. In addition, the trucks will always take the shortest way. There are M (M <= 3000) two-way roads connecting the towns, and the length of the road is 1. 
      Let SUM be the total distance of the shortest paths between all pairs of the towns. Please write a program to calculate the new SUM after one of the M roads is destroyed.

Input      The input contains several test cases. 
      The first line contains two positive integers N, M. The following M lines each contains two integers u, v, meaning there is a two-way road between town u and v. The roads are numbered from 1 to M according to the order of the input. 
      The input will be terminated by EOF.

Output      Output M lines, the i-th line is the new SUM after the i-th road is destroyed. If the towns are not connected after the i-th road is destroyed, please output “INF” in the i-th line. 
Sample Input

5 4
5 1
1 3
3 2
5 4
2 2
1 2
1 2

Sample Output

INF
INF
INF
INF
2
2 题目大意:有N个点,M条边,每次删掉一条边,问删掉该边后,所有点之间的最短路的和是多少
题解:
  只需要每个点求出其最短路的路径组成的一棵树就可以了,然后判断其边在不在,在就在求一次,就没了,

hdu 2433 Travel (最短路树)的更多相关文章

  1. hdu 2433 Travel

    http://acm.hdu.edu.cn/showproblem.php?pid=2433 题意: 求删除任意一条边后,任意两点对的最短路之和 以每个点为根节点求一个最短路树, 只需要记录哪些边在最 ...

  2. HDU 2433 Travel (最短路,BFS,变形)

    题意: 给出一个图的所有边,每次从图中删除一条边,求任意点对的路径总和(求完了就将边给补回去).(有重边) 思路: #include <bits/stdc++.h> using names ...

  3. hdu 2433 Travel(还不会)

    Problem Description       One day, Tom traveled to a country named BGM. BGM is a small country, but ...

  4. hdu 3409 最短路树+树形dp

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3409 参考博客:http://www.cnblogs.com/woaishizhan/p/318981 ...

  5. Connections between cities HDU - 2874(最短路树 lca )

    题意: 给出n个点m条边的图,c次询问 求询问中两个点间的最短距离. 解析: Floyd会T,所以用到了最短路树..具体思想为: 设k为u和v的最近公共祖先 d[i] 为祖结点到i的最短距离  则di ...

  6. LA4080/UVa1416 Warfare And Logistics 最短路树

    题目大意: 求图中两两点对最短距离之和 允许你删除一条边,让你最大化删除这个边之后的图中两两点对最短距离之和. 暴力:每次枚举删除哪条边,以每个点为源点做一次最短路,复杂度\(O(NM^2logN)\ ...

  7. BZOJ1975[Sdoi2010]魔法猪学院——可持久化可并堆+最短路树

    题目描述 iPig在假期来到了传说中的魔法猪学院,开始为期两个月的魔法猪训练.经过了一周理论知识和一周基本魔法的学习之后,iPig对猪世界的世界本原有了很多的了解:众所周知,世界是由元素构成的:元素与 ...

  8. BZOJ4356Ceoi2014 Wall——堆优化dijkstra+最短路树

    题目描述 给出一个N*M的网格图,有一些方格里面存在城市,其中首都位于网格图的左上角.你可以沿着网络的边界走,要求你走的路线是一个环并且所有城市都要被你走出来的环圈起来,即想从方格图的外面走到任意一个 ...

  9. 51nod 1443 路径和树(最短路树)

    题目链接:路径和树 题意:给定无向带权连通图,求从u开始边权和最小的最短路树,输出最小边权和. 题解:构造出最短路树,把存留下来的边权全部加起来.(跑dijkstra的时候松弛加上$ < $变成 ...

随机推荐

  1. B/S和C/S示意图

    B/S C/S

  2. SpringCloud开发学习总结(一)—— 基础知识

    1:Dubbo和Spring Cloud的关系 就我个人对这两个框架的使用经验和理解,打个不恰当的比喻:使用Dubbo构建的微服务架构就像组装电脑,各环节我们的选择自由度很高,但是最终结果很有可能因为 ...

  3. 打包Scala jar 包的正确步骤

    实验目的:打包可运行的scala jar,上传到spark集群,提交执行 1.idea中编译运行代码,可成功运行 2.修改2处代码//只配置appName,其他配置项注释掉val conf=new S ...

  4. VS项目属性配置总结

    以下是针对VS2013下的VC++项目: Debug和Release说明: Debug 通常称为调试版本,它包含调试信息,并且不作任何优化,便于程序员调试程序.Release 称为发布版本,它往往是进 ...

  5. Sql Server中清空所有数据表中的记录

    Sql Server中清空所有数据表中的记录 清空所有数据表中的记录: 代码如下:exec sp_msforeachtable  @Command1 ='truncate table ?'删除所有数据 ...

  6. ButterKnife 在父类 点击事件没反应的解决方案

    在用继承的方式实现butterKnife的封装的时候遇到问题, butterKnife就在baseActivity中绑定的,但是父类中公共控件点击事件无效.找了半天原因,原来是子类和父类定义的点击方法 ...

  7. jQuery 返回顶部效果

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. CE工具里自带的学习工具--第二关

    图解:

  9. Windows文件自删除的两种方法

    可执行模块的自删除技术已经被讨论的很多, 有很多极富创意的思路和想法被提出, 但有些似是而非的方案往往使人误入歧途. 举个例子来说, 很多文章认为下面的一小段代码可以实现自删除:void main(v ...

  10. 04Struts2的配置文件

    Struts2的配置文件 1.1 struts.xml中的标签详解 1.1.1     constant标签 作用: 用于修改struts2中的常量 属性: name:指定常量的key value:指 ...