update Head and Dijkstra's algorithm