## Editorial for GlobeX Cup '18 S4 - Reversed Dijkstra's

**only**when stuck, and

**not to copy-paste code from it**. Please be respectful to the problem author and editorialist.

**Submitting an official solution before solving the problem yourself is a bannable offence.**

Author:

For the first subtask, note that . This means that the graph is a tree, meaning that there is only *one* path from to . Thus we can just run a BFS or DFS from to , with the answer being .

**Time Complexity:**

For the second subtask, it suffices to simply check every possible path in the graph from to and then get the smallest of all those paths. One method of doing this is a DFS traversal of every path in the graph starting from .

Note that due to the number of edges () in the first subtask, this approach also works for it.

**Time Complexity:**

For the final subtask, note that we can use a visited array to skip redundant paths. Two paths from to a vertex are redundant if they both have visited the same nodes. The implementation is left as an exercise to the reader.

We can prove this by looking at any two paths from to any vertex that has visited the same vertices. We can make two observations about these paths.

- Both paths have the same length, since it's not allowed to backtrack and they visited the same [amount of] vertices.
- The vertices that both paths can visit from onward are the same, since they have already visited the same vertices and the paths cannot backtrack.

These observations show that both paths are functionally the same and thus it would be redundant to search onward from any more than one of the paths.

**Time Complexity:**

Author's note: Note that this problem is extremely similar to CCO '15 P2 - Artskjid, hence the [very original] problem name.

## Comments

This comment is hidden due to too much negative feedback. Click here to view it.