atcoder#ABC229F. [ABC229F] Make Bipartite
[ABC229F] Make Bipartite
Score : points
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.
5
31 4 159 2 65
5 5 5 5 10
16
Deleting the edge connecting Vertices (weight: ), the edge connecting Vertices (weight: ), and the edge connecting Vertices (weight: ) makes the graph bipartite.
4
100 100 100 1000000000
1 2 3 4
10