naive implementation of Dijkstra's algorithm