shortest paths using matrix