#P1640. Consecutive Equipment Attack
Consecutive Equipment Attack
Consecutive Equipment Attack
lxhgww is obsessed with a game where he owns many equipments. Each equipment has two attributes with values in the range . When using an equipment, only one of its attributes can be chosen, and each equipment can be used at most once. To deal damage to the ultimate boss, the sequence of attribute values used in consecutive attacks must start at and increase by one each time, i.e., . Given the attributes of all equipments, determine the maximum number of consecutive attacks that lxhgww can perform. This problem can be solved by modeling it as a bipartite matching problem: match each required attack value (starting from ) to a unique equipment that contains that value as one of its attributes.
inputFormat
The first line contains an integer , the number of equipments. Each of the following lines contains two integers and (), representing the two attributes of an equipment.
outputFormat
Output a single integer, which is the maximum number of consecutive attacks (starting from ) that can be performed.
sample
3
1 2
2 3
1 1
3