connected components : put matched rows last