#P2319. Maximum Question Matching with Unique Tricks
Maximum Question Matching with Unique Tricks
Maximum Question Matching with Unique Tricks
In this problem, you are given a game show scenario where there are questions and distinct trick strategies available. For each question, the host offers two specific trick strategies. Each trick can only be used once overall. If you choose one of the offered tricks for a question, you are guaranteed to answer that question correctly and proceed to the next one. However, because each trick can only be used once, you might not be able to answer all questions. Your task is to determine the maximum number of questions that you can answer by selecting a valid trick strategy for each question.
Formally, you are given two integers and , and then lines follow. Each line contains two integers representing the two available trick strategies for that question. You need to assign a trick to as many questions as possible under the constraint that each trick is used at most once. This can be modeled as a bipartite matching problem, where one partition represents the questions and the other represents the trick strategies.
inputFormat
The first line contains two space-separated integers and , which denote the number of questions and the total number of trick strategies respectively.
The next lines each contain two space-separated integers. The two integers on the -th line denote the two trick strategies available for that question. It is guaranteed that all trick strategy numbers are between and .
outputFormat
Output a single integer representing the maximum number of questions that can be answered by using the trick strategies, given that each trick can be used at most once.
sample
3 3
1 2
2 3
1 3
3
</p>