handaling disconnected graphs