#abc229f. [abc229_f]Make Bipartite
[abc229_f]Make Bipartite
Problem Statement
Given is an undirected graph with vertices.
The vertices are called Vertex , Vertex , , Vertex .
For each , the graph has an undirected edge with a weight of connecting Vertex and Vertex .
Additionally, for each , the graph has an undirected edge with a weight of connecting Vertex and Vertex . (Here, Vertex stands for Vertex .)
The graph has no edge other than these edges above.
Let us delete some of the edges from this graph so that the graph will be bipartite.
What is the minimum total weight of the edges that have to be deleted?
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
5
31 4 159 2 65
5 5 5 5 10
Sample Output 1
16
Deleting the edge connecting Vertices (weight: ), the edge connecting Vertices (weight: ), and the edge connecting Vertices (weight: ) makes the graph bipartite.
Sample Input 2
4
100 100 100 1000000000
1 2 3 4
Sample Output 2
10