#P6577. 【模板】二分图最大权完美匹配
【模板】二分图最大权完美匹配
Description
Given a bipartite graph, both the left part and the right part have vertices. There are weighted edges, and it is guaranteed that a perfect matching exists.
Find a perfect matching such that the sum of the weights of the matched edges is maximized.
Input Format
The first line contains two integers , with the meaning described above.
Lines each contain three integers , describing an edge from vertex on the left part to vertex on the right part, with edge weight .
Output Format
This problem has a Special Judge.
The first line contains an integer , the answer.
The second line contains integers , where is the index of the left-part vertex that is matched with the -th vertex on the right part in the perfect matching. If there are multiple solutions, output any one of them.
5 7
5 1 19980600
4 2 19980587
1 3 19980635
3 4 19980559
2 5 19980626
1 2 -15484297
4 5 -17558732
99903007
5 4 1 3 2
Hint
Constraints
- For of the testdata, .
- For of the testdata, .
- For of the testdata, , and the testdata is guaranteed to be random.
- For of the testdata, , , . It is also guaranteed that there are no multiple edges.
The testdata was produced after a long time by a problem setter who is “good at causing failures”.
The kind “Yangcunhua” reminds you: do not forget to carefully check the range of edge weights.
The kind “Yangcunhua” reminds you again: your time complexity may only “look” correct.
Translated by ChatGPT 5
京公网安备 11011102002149号