zoukankan      html  css  js  c++  java
  • hdu 2433 Travel (最短路树)

     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条边,每次删掉一条边,问删掉该边后,所有点之间的最短路的和是多少
    题解:
      只需要每个点求出其最短路的路径组成的一棵树就可以了,然后判断其边在不在,在就在求一次,就没了,
  • 相关阅读:
    类 7.2访问控制与封装 笔记
    第七章 类(class)7.1 笔记
    10.4.3反向迭代器Reverse_iterator笔记
    10.4再探迭代器笔记
    10.3.4参数绑定 bind
    10.3lambda表达式笔记
    第10章 10.1-10.3笔记
    关于按下ctrl+z后,之后的cin失效的问题
    构造和改变一个string的其他方法
    BZOJ2527 & 洛谷3527:[Poi2011]Meteors——题解
  • 原文地址:https://www.cnblogs.com/fengzhiyuan/p/7766097.html
Copyright © 2011-2022 走看看