2573. Hub Connection plan

单点时限: 2.0 sec

内存限制: 256 MB

Partychen is working as system administrator and is planning to establish a new network in his company. There will be N hubs in the company, they can be connected to each other using cables. Since each worker of the company must have access to the whole network, each hub must be accessible by cables from any other hub (with possibly some intermediate hubs).

Since cables of different types are available and shorter ones are cheaper, it is necessary to make such a plan of hub connection, that the cost is minimal. partychen will provide you all necessary information about possible hub connections. You are to help partychen to find the way to connect hubs so that all above conditions are satisfied.

输入格式

The first line of the input contains two integer numbers: N - the number of hubs in the network (2 <= N <= 1000) and M - the number of possible hub connections (1 <= M <= 15000). All hubs are numbered from 1 to N. The following M lines contain information about possible connections - the numbers of two hubs, which can be connected and the cable cost required to connect them. cost is a positive integer number that does not exceed 106. There will always be at least one way to connect all hubs.

输出格式

Output the minimize cost of your hub connection plan.

样例

Input
4 6
1 2 1
1 3 1
1 4 2
2 3 1
3 4 1
2 4 1
Output
3
Hint
We can build net from 1 to 2 to 3 to 4,then we get the cost is 3.Of course you can get 3 by other way.

371 人解决,471 人已尝试。

493 份提交通过,共有 1829 份提交。

2.4 EMB 奖励。

创建: 15 年,3 月前.

修改: 6 年,10 月前.

最后提交: 6 天,19 小时前.

来源: 2009 华东师范大学 研究生复试

题目标签
mst