1 auto cmp = [&](const Edge& a, const Edge& b) { return a.cost > b.cost; // 小根堆:cost 小的优先 }; priority_queue, decltype(cmp)> pq(cmp); 2 struct Compare { bool operator()(const Edge& a, const Edge& b) const { return a.cost > b.cost; // 小根堆 } }; priority_queue, Compare> pq; 3 using F = function; priority_queue, F> pq( [](const Edge& a, const Edge& b){ return a.cost > b.cost; // 小根堆 } ); 4 struct Edge{ int from, to, cost; Edge(int f, int t, int c): from(f), to(t), cost(c) {} bool operator<(const Edge& other) const { return cost > other.cost; // 小根堆 } //一定是<,不能是> }