Problems like "always process the cheapest edge next" or "keep the K largest values" need quick access to the top element. priority_queue is a heap that gives the top in O(1) and inserts in O(log n). Note that it is a max-heap by default in C++, the opposite of Java, so pass greater<int> for a min-heap. It is the core of Dijkstra and top-K questions.