Optimize the GetSet function by making each node reached along the traversal point directly to the root node to shorten subsequent traversals.