#P3967. [TJOI2014] 匹配
[TJOI2014] 匹配
Description
There are single boys and single girls. The happiness of pairing boy with girl is .
A matching is an arrangement of these boys and girls such that each boy has exactly one girlfriend and each girl has exactly one boyfriend.
The happiness of a matching is the sum of the happiness values of these pairs.
The classic task is to compute the maximum possible happiness, i.e., a maximum-weight perfect matching (also called an "assignment"). However, the maximum-weight perfect matching is not always unique. You need to compute the intersection of all maximum-weight perfect matchings.
Input Format
The first line contains a positive integer .
Then follows an matrix , where denotes the happiness of pairing boy with girl .
Output Format
On the first line, output the happiness of the maximum-weight perfect matching. Then output several lines, each containing a pair of integers and , indicating that boy and girl appear in the intersection of all maximum-weight perfect matchings, in increasing order of .
3
1 1 1
2 1 1
1 1 1
4
2 1
Hint
- For 30% of the testdata, .
- For 100% of the testdata, , .
Translated by ChatGPT 5
京公网安备 11011102002149号