#P10046. [CCPC 2023 北京市赛] 哈密顿
[CCPC 2023 北京市赛] 哈密顿
Problem Description
Given pairs .
Consider a weighted complete directed graph with nodes, where the edge from to has weight .
Find a Hamiltonian cycle in that maximizes the sum of the weights of the edges it traverses, and output this maximum value.
Input Format
The first line contains an integer , representing the number of pairs. The next lines each contain two integers , representing each pair. It is guaranteed that among the numbers in the pairs, all numbers are pairwise distinct.
Output Format
Output one integer on a single line, representing the maximum total edge weight of a Hamiltonian cycle.
3
1 10
8 2
4 5
10
Hint
Consider the Hamiltonian cycle . The sum of edge weights is . It can be proven that no Hamiltonian cycle has a total edge weight exceeding , so the answer is .
Translated by ChatGPT 5