first full dijkstra's implementation