Implementation of dijkstra's algorithm to find the closest not traversed edge