handle graph which is not connected