Adding connected islands code.

This is a problem I didn't do very well on; I was too
centered around the 'graph' part of the problem and not
thinking of a more straightforward solution.