Implementation of Union find Algorithm
<p>I have a series of Key value pairs. Each Key has 2 values. Values of Keys may coincide.
Initially, I start with Key1, ValueKey1, ValueKey2 are stored in a set (maybe array).</p>

<p>Now for each consecutive Keyi, I check if Valuei and Valuei+1 are in the set. If any one of them is in the set, then join the set. </p>

<p>Else if both KeyValues are present in a set, discard that key.</p>

<p>How can I implement this thing using C++, I have very little idea, so if possible a code snippet or a hint would be really helpful.</p>
