Use Bellman-Ford to resolve POJ3169 Layout