I&#x27;m thinking about how I&#x27;d implement CHM. I think I&#x27;d use a union-find data structure to generate the acyclic graph, as in Kruskal&#x27;s algorithm. This would fit into an N-element integer vector. After finding the acyclic graph (forest), I&#x27;d represent the forest implicitly in another N-element integer vector, for finding the vertex weights.<p>You can take advantage of the graph being just a forest of trees and use simpler data structures.