Hamiltonian Circuit
Time limit1sMemory limit2048 MB
- Level
Not classified yet
- Solved
- No attempts yet
Problem
You are given pairs of integers .
Consider a weighted directed complete graph with vertices, where the weight of the edge from () to () is .
Find a Hamiltonian circuit in whose total edge weight is maximized, and print this maximum value.
Input
The first line contains an integer (), the number of pairs.
Each of the next lines contains two integers and (), describing one pair.
You may assume that all integers and are pairwise distinct.
Output
Print a single integer on one line: the maximum total weight of a Hamiltonian circuit.
Hint
Take the circuit in the example. Its edge weights are . No Hamiltonian circuit has a total weight above 10, so the answer is 10.