wrote a function that converts a directed acyclic graph into a tree (pytree structure)