#CJam, 90 bytes
This is based on a iterative flood fill explained herehere and can be golfed a lot!
q~:Q{:IQ3/S*Sca5*+:T;G,G*{:AT=1$={[WXZ5 4_~_)_)]Af+Tf=AT='#a+&,g{TA'#t:T;}*}*}%;aT\/,3<},p Requires the input in order of ABCDEFGH like:
[0 1 1 2 1 0 5 5 1] and output is the connected nodes:
[1 1 2 1 5 5 1] Brief Explanation
- First, I iterate over the input array for each label.
- In each iteration, I perform floodfill to figure out disconnected nodes.
- If the number of disconnected nodes is greater than 1, then that label is disconnected.
- 1 because a label can have just 1 occurrence in the input array too.
- Then I simply filter out disconnected labels and print the array.
Full explanation to follow