编程介的小学生 2017-04-20 10:07 采纳率: 20.5%
浏览 1096
已采纳

IP-TV

A consortium of European Internet providers manages a large backbone network, with direct links (connections) between a large number of European cities. A link between a pair of cities is bidirectional. The transmission of a message in a link has an associated cost. As it is common in the Internet, it is possible to use a(unbounded) sequence of direct links to indirectly transfer data between any pair of cities.

For allowing the broadcast of TV programs using this backbone, it is necessary to continuously send data to all nodes in the network. For helping to minimize costs, it is necessary to select the network links that will be used for transmitting data. The set of selected links must be connected and include all nodes in the network.

For helping the consortium to manage its network, you have been asked to create a program that computes the minimum cost for transmitting data to all cities of the backbone.

Given a set of network links, compute the minimum transmission cost for reaching all nodes.

Input

A positive integer P in a single line followed by a sequence of P test cases. The first line of the each test case contains a positive integer M, not greater than 2,000, with the number of cities that have network connections. The second line contains an integer N not greater than 50,000, with the number of existing links. Each of the following N lines contains the representation of a link. Each line contains two strings and one integer, separated by empty spaces, B E C, where B and E are the city names of the endpoints of the network link, with no more than 8 characters, and C is a positive integer, not greater than 30, representing the cost of transmitting in the link.

Output

The output consists of one single line that contains an integer with the minimum transmission cost for sending data to all cities.

Sample Input

1
4
5
lisbon london 6
lisbon paris 5
london paris 1
london berlin 2
paris berlin 10
Sample Output

8

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-05-05 04:17
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么