title: combine pairs of integers based on common element
body: <p>suppose I have pair of integers for example (1,3), (5,6), (7,8), (3,9) then I want to combine this pairs into unique sets based on common element amongst them i.e. I can combine (1,3) and (3,9) because 3 is common between them, So final output for above input should be like this (1,3,9), (5,6), (7,8)
  One way could be to iterate through this array and based on common elements combine it and delete second pair from array which I suppose is time consuming.
  What is the efficient way to do this in C/C++ ?</p>