Ring-transformation graphs and their application to degenerate heterocyclic rearrangements