hdu 2433 Travel (最短路树)
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 (最短路树)的更多相关文章
- hdu 2433 Travel
http://acm.hdu.edu.cn/showproblem.php?pid=2433 题意: 求删除任意一条边后,任意两点对的最短路之和 以每个点为根节点求一个最短路树, 只需要记录哪些边在最 ...
- HDU 2433 Travel (最短路,BFS,变形)
题意: 给出一个图的所有边,每次从图中删除一条边,求任意点对的路径总和(求完了就将边给补回去).(有重边) 思路: #include <bits/stdc++.h> using names ...
- hdu 2433 Travel(还不会)
Problem Description One day, Tom traveled to a country named BGM. BGM is a small country, but ...
- hdu 3409 最短路树+树形dp
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3409 参考博客:http://www.cnblogs.com/woaishizhan/p/318981 ...
- Connections between cities HDU - 2874(最短路树 lca )
题意: 给出n个点m条边的图,c次询问 求询问中两个点间的最短距离. 解析: Floyd会T,所以用到了最短路树..具体思想为: 设k为u和v的最近公共祖先 d[i] 为祖结点到i的最短距离 则di ...
- LA4080/UVa1416 Warfare And Logistics 最短路树
题目大意: 求图中两两点对最短距离之和 允许你删除一条边,让你最大化删除这个边之后的图中两两点对最短距离之和. 暴力:每次枚举删除哪条边,以每个点为源点做一次最短路,复杂度\(O(NM^2logN)\ ...
- BZOJ1975[Sdoi2010]魔法猪学院——可持久化可并堆+最短路树
题目描述 iPig在假期来到了传说中的魔法猪学院,开始为期两个月的魔法猪训练.经过了一周理论知识和一周基本魔法的学习之后,iPig对猪世界的世界本原有了很多的了解:众所周知,世界是由元素构成的:元素与 ...
- BZOJ4356Ceoi2014 Wall——堆优化dijkstra+最短路树
题目描述 给出一个N*M的网格图,有一些方格里面存在城市,其中首都位于网格图的左上角.你可以沿着网络的边界走,要求你走的路线是一个环并且所有城市都要被你走出来的环圈起来,即想从方格图的外面走到任意一个 ...
- 51nod 1443 路径和树(最短路树)
题目链接:路径和树 题意:给定无向带权连通图,求从u开始边权和最小的最短路树,输出最小边权和. 题解:构造出最短路树,把存留下来的边权全部加起来.(跑dijkstra的时候松弛加上$ < $变成 ...
随机推荐
- [转]Asp.net MVC中Html.Partial, RenderPartial, Action,RenderAction 区别和用法
本文转自:http://www.cnblogs.com/gesenkof99/archive/2013/06/03/3115052.html Partial 和RenderPartial:这两个的性质 ...
- Java_JDBC连接数据库
package com.accp.dao; import java.sql.Connection; import java.sql.DriverManager; import java.sql.Pre ...
- 初学Ajax
AJAX即“Asynchronous Javascript And XML”(异步JavaScript和XML),是指一种创建交互式网页应用的网页开发技术. AJAX = 异步 JavaScript和 ...
- Hadoop YARN学习之核心概念(2)
Hadoop YARN学习之核心概念(2) 1. Hadoop 2.X YARN引入的新服务 1.1 新的ResourceManager纯碎作为资源调度器,是集群资源的唯一仲裁者: 1.2 用户应用程 ...
- Compiler 1.6.5 —1.6.7
Compiler 1.6.5 —1.6.7 Dynamic Scope Technically, any scoping policy is dynamic if it is based on fa ...
- 调试SQL Server的存储过程及用户定义函数
分类: 数据库管理 2005-06-03 13:57 9837人阅读 评论(5) 收藏 举报 sql server存储vb.net服务器sql语言 1.在查询分析器中调试 查询分析器中调试的步骤如下: ...
- Can't find bundle for base name messages.AndroidJpsBundle, locale zh_CN
从http://www.android-studio.org/网站上下载了一个Android Studio 3.0的非安装版本(android-studio-ide-171.4408382-wind ...
- 【译】x86程序员手册35-9.8异常条件
译注:一些异常没有翻译,因为看书时主要为了理解linux代码,所以代码中没有主要使用的就没有仔细看.这部分内容后期再看时再进行翻译. 9.8 Exception Conditions 异常条件 The ...
- SCCM大致安装过程,参考前辈教程完成部署
本安装sccm主站点服务器准备 参考:http://stephen1991.blog.51cto.com/8959108/1529864 1. 准备三台服务器 ,注:所有服务器需要安装 .net3. ...
- mysql-oracle
1.oracle数据崩导入时部分字段数据太长导入失败:原因是两边oracle字符集不一致 https://www.cnblogs.com/baoposhou/p/5669778.html 2.orac ...