Source: https://homes.cs.washington.edu/~arvind/papers/reversepaths.pdf