Separate implementation of graph and tree creation to speed it up. Graph implementation maps upfront all locations to sequences of nodes, tree implementation uses a per-parent map to keep track of a different node per location per parent.