Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|

Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |

Language: Telephone Lines
Description Farmer John wants to set up a telephone line at his farm. Unfortunately, the phone company is uncooperative, so he needs to pay for some of the cables required to connect his farm to the phone system. There are The B, with length _{i}L (1 ≤ _{i}L ≤ 1,000,000) units if used. The input data set never names any {_{i}A, _{i}B} pair more than once. Pole 1 is already connected to the phone system, and pole_{i} N is at the farm. Poles 1 and N need to be connected by a path of cables; the rest of the poles might be used or might not be used.As it turns out, the phone company is willing to provide Farmer John with Determine the minimum amount that Farmer John must pay. Input * Line 1: Three space-separated integers: B, and _{i}L _{i}Output * Line 1: A single integer, the minimum amount Farmer John can pay. If it is impossible to connect the farm to the phone company, print -1. Sample Input 5 7 1 1 2 5 3 1 4 2 4 8 3 2 3 5 2 9 3 4 7 4 5 6 Sample Output 4 Source |

[Submit] [Go Back] [Status] [Discuss]

All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di

Any problem, Please Contact Administrator