# HDU 2433 - Travel

138人阅读 评论(0)

Description

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 

bfs 时间复杂度 E ， 但如果每次拆路都对所有节点重新求最短路 复杂度则是 E*V*E 还多个case 可能不过

①不优化的复杂度是O(E*E*V)，也是临界可解，以后遇到这样的题目要往优化的方面想。

0
0

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：7572次
• 积分：390
• 等级：
• 排名：千里之外
• 原创：31篇
• 转载：9篇
• 译文：0篇
• 评论：0条
评论排行