made it work for dijkstra and bfs