Problem link
One of x,y is obviously one of a1,b1. For example, let's fix who is x from the first pair. Then you need to check that there exists some y such that all pairs that don't contain x, contain y. For this, you can remember in the array for each value how many pairs that don't contain x contain this value, and then you need to check that in the array there exists some value that is equal to the number of pairs left.
A solution in c++
0 Comments
If you have any doubts, Please let me know