finding the components in a graph