I want to list all the terminal node with respect to a node in graph, my code does work however in a complicated graph it not working efficiently. AS you can see I am using