first part of dijkstra explanation