rewriting countComponents with regorous initialisation of a component per vertex