how about a visited bool flag on each node. make it false on all node then start visit the graph from a root to all its connected node recursively and set the visited flag to true for each visited node when finished review all node, those with the false to false are disconnected, voila! :) For your information this is roughly what the GC is doing to find object to collect!! ^^
My programming get away... The Blog... DirectX for WinRT/C# since 2013! Taking over the world since 1371!