Dijkstra algorithm, need fully understanding the sort rules