默认堆的弹出顺序

👁️ 1 人浏览 💬 0 人评论 ❤️ 添加收藏

运行下面这段程序:

#include <algorithm>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

typedef long long ll;
const ll INF = 1000000000;                       // 走不到的点记这个值,输出时写成 -1
using Graph = vector<vector<pair<int, int>>>;    // g[u] 里放 (邻居 v, 边权 w)

int main() {
    priority_queue<pair<ll, int>> pq;
    pq.push({5, 1});
    pq.push({2, 2});
    pq.push({9, 3});
    string s;
    while (!pq.empty()) {
        s += (s.empty() ? "" : "/") + to_string(pq.top().first);
        pq.pop();
    }
    cout << s << endl;
}

(本题用 g++ -std=c++17 -O0 编译。)

提交你的答案
请登录后提交答案。
去登录
代码编辑器
Ctrl + Enter 运行
本次输入:
输出:

                        
👩‍🏫
AI
💬 题目评论

全部评论