There is a undirected connected graph with
You wish to remove all edges in the graph, however there is a cost incurred when removing a edge which is the sum of the weights of the nodes of the removed edge when the edge is removed.
You can remove the edges in any order, however immediately after removing an edge the weights of the two ndoes that was connected to the edge are swapped.
Find the minimum cost needed to remove all the edges.
Subtasks # | Score | Constraits |
---|---|---|
1 | 10 | |
2 | 20 | |
3 | 13 | |
4 | 24 | |
5 | 33 | - |
The first line contains
The next line contains
The next line contains
Output the minimum cost
Sample Input 1 | Sample Output 1 |
3
|
7
|
An optimal solution is to disconnect nodes
Subtask | Score |
---|---|
1 | 10 |
2 | 20 |
3 | 13 |
4 | 24 |
5 | 33 |