

Time Limit: 2.5 sec / Memory Limit: 1024 MB
配点 : 点
注意
この問題に対する言及は、2020/6/6 18:00 JST まで禁止されています。言及がなされた場合、賠償が請求される可能性があります。 試験後に総合得点や認定級を公表するのは構いませんが、どの問題が解けたかなどの情報は発信しないようにお願いします。
問題文
スーヌケ王国には 個の街があります。
王国には 本の道が存在していて、 番目の道は、街 , を双方向に繋いでいます。 ある道を 回利用するためには、通行料として 円を払う必要があります。 任意の街から出発して、いくつかの道を経由することで任意の街に辿り着けることが分かっています。
王国の行商人であるタカーハ氏は現在街 にいて、これから 個の街 で取引をしたいと思っています。
街 から出発して 個の街それぞれを少なくとも 回は訪れるために、タカーハ氏が払う必要のある通行料の合計は最小で何円でしょうか。 最終的に街 に戻ってくる必要はありません。
同じ道を複数回利用するとき、その都度通行料を払う必要があることに注意してください。
制約
- 入力は全て整数である。
- のとき
- のとき
入力
入力は以下の形式で標準入力から与えられる。
出力
タカーハ氏が払う必要のある通行料の合計の最小値を整数として出力せよ。
入力例 1Copy
3 2 1 2 2 3 2 2 1 3
出力例 1Copy
3
まず街 から街 に移動して、その後再び街 へと戻り、次に街 へと移動することで、 合計 円の通行料で街 と街 を訪れることができます。
入力例 2Copy
5 5 1 2 1 3 1 4 1 5 2 3 1 3 2 3 5
出力例 2Copy
4
Score : points
Warning
Do not make any mention of this problem until June 6, 2020, 6:00 p.m. JST. In case of violation, compensation may be demanded. After the examination, you can reveal your total score and grade to others, but nothing more (for example, which problems you solved).
Problem Statement
The Kingdom of Soonuke has towns.
There are roads in the kingdom. The -th road connects Town and bidirectionally. You need to pay the toll of yen each time you use a road. We know that any town can be reached from any town by using some number of roads.
Takaaha, a merchant, is now at Town and wants to make transactions in towns
What is the minimum total toll Takaaha needs to pay when he starts at Town and visit each of the towns at least once? He does not need to come back to Town in the end.
Note that using the same road multiple times will cost you the toll that number of times.
Constraints
- All values in input are integers.
- If , .
- If , .
Input
Input is given from Standard Input in the following format:
Output
Print the minimum total toll Takaaha needs to pay, as an integer.
Sample Input 1Copy
3 2 1 2 2 3 2 2 1 3
Sample Output 1Copy
3
If we go from Town to Town , then go back to Town , then go to Town , we can visit the towns and with the total toll of yen.
Sample Input 2Copy
5 5 1 2 1 3 1 4 1 5 2 3 1 3 2 3 5
Sample Output 2Copy
4