Minimize shortest path by adding weight-1 edges | MathWorks Interview Question