

Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 点
問題文
AtCoder国には から の番号がついた 個の街と から の番号がついた 本の道路があります。
道路 は街 と街 を双方向に結び、長さは です。どの街同士も、いくつかの道路を通って互いに行き来することができます。
いずれかの街を出発し、道路による移動で全ての街を 度以上訪れるための移動距離の最小値を求めてください。
制約
- 入力は全て整数である
- どの街同士も、いくつかの道路を通って互いに行き来できる
入力
入力は以下の形式で標準入力から与えられる。
出力
答えを出力せよ。
入力例 1Copy
4 1 2 2 1 3 3 1 4 4
出力例 1Copy
11
と移動すると移動距離の合計は となり、これが最小値です。
最初の街に戻ってくる必要はないことに注意してください。
入力例 2Copy
10 10 9 1000000000 9 8 1000000000 8 7 1000000000 7 6 1000000000 6 5 1000000000 5 4 1000000000 4 3 1000000000 3 2 1000000000 2 1 1000000000
出力例 2Copy
9000000000
オーバーフローに注意してください。
Score : points
Problem Statement
In the nation of AtCoder, there are cities numbered to and roads numbered to .
Road connects cities and bidirectionally, and its length is . Any pair of cities can be reached from each other by traveling through some roads.
Find the minimum travel distance required to start from a city and visit all cities at least once using the roads.
Constraints
- All input values are integers.
- Any pair of cities can be reached from each other by traveling through some roads.
Input
The input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1Copy
4 1 2 2 1 3 3 1 4 4
Sample Output 1Copy
11
If you travel as , the total travel distance is , which is the minimum.
Note that you do not need to return to the starting city.
Sample Input 2Copy
10 10 9 1000000000 9 8 1000000000 8 7 1000000000 7 6 1000000000 6 5 1000000000 5 4 1000000000 4 3 1000000000 3 2 1000000000 2 1 1000000000
Sample Output 2Copy
9000000000
Beware overflow.