USTC 1123 Two Hospitals

Time Limit: 2000ms
Memory Limit: 65536kb
Description

In the highland, people live in towns. There are roads between pairs of towns, so that all the towns are connected by paths. Because the roads are different in length and surface, each road has a constant traveling time.

Now, the government wants to build two hospitals in two of these towns. Which two towns should be chosen to locate the two hospitals?

Let ti denotes the time town i travel to its nearer hospital by a path costing the shortest time. The time traveling through a path is the sum of traveling time of each road on the path. The time traveling inside towns is omitted.

The principle for locating the two hospitals is that the maximum ti must be minimized. If there are multi roads between two towns, only the lowest cost road will be considered. There may exists roads from one town to itself, but in our scene, these roads are useless.

Now, given the roads and their traveling time, it is your job to find the two towns to build the two hospitals. Fortunately, in our cases, the solution of the problem is unique.

Input

The first line of input is an integer k, which is the number of cases. The following 2k lines contain k cases.

In each case, the first line contains two integers N and E, which are the number of towns and the number of roads in this case. All the towns in the case are labeled as 1, 2, ..., N. (2 <= N <= 500, N-1 <= E <= 2000). The second line contains 3E integers, that is a list as u1, v1, w1, ..., uE, vE, wE. ui and vi denotes the two relating towns of the i-th road without direction, and wi is the cost time of the road.

Output

For case, output the labels of the two towns in one line, with the smaller label in front.

Sample Input
1
5 8
1 2 6 1 3 2 1 4 4 3 5 4 2 5 2 2 4 3 1 2 4 4 4 1
Sample Output
1 2
来源:34th ACM/ICPC Asia Regional, Hefei, Preliminary
解题:
2009年的合肥网络赛最后一题,题目意思是要求在一些城镇里面,建立两个医院,使得每个城镇到医院的距离最短(任意一个医院即可)。
考察弗洛伊德算法和暴力枚举。先求出每个城镇间最短距离,再依次枚举,比如:先假设医院设在1,2城镇,计算其他城镇到这两个城镇的总
距离;再假设1,3城镇,计算其他城镇到这两个城镇距离·····最后比较哪个假设的总距离是最短的,即所要求的。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值