Explanation for B. Pairs
The answer I submitted for B. Pairs was too slow to pass the tests, so I went back after the contest to view others solutions. Then I discovered that I was missing some key assumptions.
If there is an answer, one of the numbers from the solution pair will be one of the two numbers in the very first given pair
If you choose a number K from the first pair using Assumption 1, that number will either occur in every single following pair, or there will be a point where you encounter a pair where K is not one of the numbers. At this point you must choose a second number L which will be again one of the two numbers in the currently encountered pair.
The answer is "YES" If and only if for every pair you encounter, at least one of the chosen numbers K or L are one of the two numbers in the current pair
Capture all the pairs given.
Use Assumption 1 to choose one of the two numbers from the first pair (K). (Choose the one you haven't used if you've done this step before).
Iterate through all the pairs until.
- a) you reach the end of the pairs which means go to step #SUCCESS.
- b) you encounter a pair where K is not in the pair.
Choose one of the two numbers from the current pair (L) (Choose the one use didn't use last time [first number or second number]).
Continue iterating through pairs while at least one of the numbers in the current pair is K or L.
- a) you reached the end of the pairs, go to step #7
- b) you encountered a pair where neither K or L are one of the two numbers, go to step #4 if you still haven't tried another number for L.
- c) you've tried both numbers for L, but you still haven't tried a different number for K, go back to step #2.
- d) you've tried both numbers for K, and both numbers for L for every K. Nothing left to do, go to #8.
Print "YES" and exit program
Print "NO" and exit program