For calculating SP using Djikstra