Testing
InterviewTime limit2sMemory limit1024 MB
Given n cards that each hold two different numbers from 1 to n+1, find the fewest cards to change so that one number appears on every card.
- Level
Easy3 of 10
- Topics
- Array, Hash map, Implementation
- Solved
- No attempts yet
Statement
Sarah Connor needs to prove to Dr. Silberman, the chief physician of the clinic, that she is sane and capable of making sound judgments before she can see her son. As one of the tests, the doctor gives her the following problem.
Dr. Silberman: You broke my arm!
Sarah Connor: The human body has 215 bones. That was only one.
Terminator 2: Judgment Day
Dr. Silberman lays cards on the table. Each card has two natural numbers, and each number is between 1 and . No card has the same number written twice. No two cards have the same pair of numbers.
Sarah may pick some cards and change the numbers written on them. After her changes, there must be one number that is written on every card. The conditions above must still hold: every card is unique, and the two numbers on each card are different.
Sarah's task is to do this by changing as few cards as possible. Help her do it.
Input
The first line contains one integer (), the number of cards on the table. The next lines each contain two different numbers from 1 to , the numbers written on the cards.
It is guaranteed that no two cards have the same pair of numbers, and no two cards have numbers that differ only in order.
Output
Print one line with the integer , the minimum number of cards Sarah Connor must change to pass the test.