#agc028c. [agc028_c]Min Cost Cycle
[agc028_c]Min Cost Cycle
Problem Statement
We have a directed weighted graph with vertices. Each vertex has two integers written on it, and the integers written on Vertex are and .
In this graph, there is an edge from Vertex to Vertex for all pairs , and its weight is .
We will consider a directed cycle in this graph that visits every vertex exactly once. Find the minimum total weight of the edges in such a cycle.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the minimum total weight of the edges in such a cycle.
Sample Input 1
3
1 5
4 2
6 3
Sample Output 1
7
Consider the cycle . The weights of those edges are , and , for a total of . As there is no cycle with a total weight of less than , the answer is .
Sample Input 2
4
1 5
2 6
3 7
4 8
Sample Output 2
10
Sample Input 3
6
19 92
64 64
78 48
57 33
73 6
95 73
Sample Output 3
227