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. 424 Longest Repeating Character Replacement 替换后的最长重复字符

    给你一个仅由大写英文字母组成的字符串,你可以将任意位置上的字符替换成另外的字符,总共可最多替换 k 次.在执行上述操作后,找到包含重复字母的最长子串的长度.注意:字符串长度 和 k 不会超过 104. ...

  2. bat 时间 的运算与提取

    比如在系统中date这个环境变量的值为 -- 星期六 年------%date:~,% 表示从左向右指针向右偏0位,然后从指针偏移到的位置开始提取4位字符,结果是2011 月------%date:~ ...

  3. 梅沙教育APP简单分析-版本:iOS v1.2.21-Nathaneko-佳钦

    梅沙教育APP简单分析 时间:2017年6月6日 版本:iOS v1.2.21 分析人:Nathaneko-佳钦 备注:仅仅是个人一些简单的分析与见解,非正式产品分析报告,未体验购买相关功能,可能存在 ...

  4. Ryubook_1_switch_hub_部署执行

    一.环境: mininet.ovs.Ryu. 二.实验过程: 1.搭建拓扑: 执行sudo mn --topo single,3 --mac --switch ovsk --controller re ...

  5. ROS在rviz中实时显示轨迹(nav_msgs/Path消息的使用)

    消息结构说明nav_msgs/Path.msg结构#An array of poses that represents a Path for a robot to followHeader heade ...

  6. CAD参数绘制圆弧(网页版)

    在CAD设计时,需要绘制圆弧,用户可以在图面点圆弧起点,圆弧上的一点和圆弧的终点,这样就绘制出圆弧. 主要用到函数说明: _DMxDrawX::DrawArc2 由圆弧上的三点绘制一个圆弧.详细说明如 ...

  7. MFC如何设置窗口最前

    首先,放到最前 this->SetWindowPos(&wndTopMost,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);//使窗口总是在最前面 this->Se ...

  8. SQLSTATE=2300

    在powerdesigner将表的结构运用于数据库的时候报的错. 目标: 在Hibernate中使用多表级联的插入操作. 解决办法: 将navicat中的mysql数据库表删除, 手动创建 原因: p ...

  9. 第2节 hive基本操作:6、7、8

    第1节 hive安装:6.hive的基本操作:7.创建数据库的语法:8.hive当中创建内部表的语法. hive的基本操作: 创建数据库与创建数据库表操作 创建数据库操作:create databas ...

  10. 编译压缩代码 MFCompress-src-1.01 :对‘***’未定义的引用

    提示 MFCompressD.o:在函数‘main’中:MFCompressD.c:(.text.startup+0x34a): 警告: the use of `tempnam' is dangero ...