dijkstra's algorithm: implementation without a heap