Type: Default 1000ms 256MiB

agc028c

You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.

Score : 700 points

Problem Statement

We have a directed weighted graph with N vertices. Each vertex has two integers written on it, and the integers written on Vertex i are Ai and Bi.

In this graph, there is an edge from Vertex x to Vertex y for all pairs 1x,yN, and its weight is min(Ax,By).

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

  • 2N105
  • 1Ai109
  • 1Bi109
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A1 B1
A2 B2
:
AN BN

Output

Print the minimum total weight of the edges in such a cycle.


Sample Input 1Copy

Copy
3
1 5
4 2
6 3

Sample Output 1Copy

Copy
7

Consider the cycle 1321. The weights of those edges are min(A1,B3)=1, min(A3,B2)=2 and min(A2,B1)=4, for a total of 7. As there is no cycle with a total weight of less than 7, the answer is 7.


Sample Input 2Copy

Copy
4
1 5
2 6
3 7
4 8

Sample Output 2Copy

Copy
10

Sample Input 3Copy

Copy
6
19 92
64 64
78 48
57 33
73 6
95 73

Sample Output 3Copy

Copy
227

ad-hoc 选讲——liangzexian1

Not Attended
Status
Done
Rule
ACM/ICPC
Problem
6
Start at
2024-9-25 10:30
End at
2024-9-28 10:30
Duration
72 hour(s)
Host
Partic.
17