Route check
This is called a route check problem , and it has a polynomial solution.
The main idea (see the link for more details) is that it is easy to solve for the Euler path (where we meet each edge every time), but for some graphs, only the Euler path is possible.
In particular, the graph must be connected and have either 0 or 2 vertices of odd degree.
However, this can be generalized to other graphs by adding additional edges in the cheapest way, which will give a graph that has an Euler path. (Note that we added more edges so that we can move around the edges several times on the original graph.)
The way to choose the best way to add additional edges is the maximum matching problem, which can be solved in O (n ^ 3).
PS
By the way, I wrote a simple demo earlier ( link to the game ) for a planar problem with maximum resolution. The solution to this problem is based on the exact same route check :)
EDIT
I just noticed from the comments that in your particular case, your chart may be a tree.
If so, then I find the answer a lot simpler, since you just need to do DFS over the tree to find the shallow subtree first.
For example, suppose you have a tree with edges S-> A and S-> A-> B. S has two subtrees, and you should first visit A ββbecause it is smaller.
The total edges visited will be equal to the number of edges visited in full DFS, minus the depth of the last leaf visited, so to minimize the total edges you want to maximize the depth of the last leaf and therefore visit the shallow subtree first.