"Three partition refinement algorithms" - читать интересную книгу автора (R.Paige, R.E.Tarjan)