It might be worth considering adding support for edge weights instead of assuming all edges are length 1.