Update priority queue
pq . push ( [ neighbor [ 1 ] + top [ 0 ] , neighbor [ 0 ] , top [ 2 ] - 1 ] ) ; } } pq . sort ( ( a , b ) => { if ( a [ 0 ] == b [ 0 ] ) return b [ 1 ] - a [ 1 ] return b [ 0 ] - a [ 0 ] ; } ) ; }