implemented with PriorityQueue