calculate manually the shortest pathway of graph