hdu 2433 Travel (最短路树)
Posted Kaiser
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 (最短路树)的主要内容,如果未能解决你的问题,请参考以下文章
BZOJ1576 [Usaco2009 Jan]安全路经Travel
[Usaco2009 Jan]安全路经Travel BZOJ1576 Dijkstra+树链剖分+线段树