34 lines
778 B
C++
34 lines
778 B
C++
1
|
||
auto cmp = [&](const Edge& a, const Edge& b) {
|
||
return a.cost > b.cost; // 小根堆:cost 小的优先
|
||
};
|
||
|
||
priority_queue<Edge, vector<Edge>, decltype(cmp)> pq(cmp);
|
||
|
||
2
|
||
struct Compare {
|
||
bool operator()(const Edge& a, const Edge& b) const {
|
||
return a.cost > b.cost; // 小根堆
|
||
}
|
||
};
|
||
|
||
priority_queue<Edge, vector<Edge>, Compare> pq;
|
||
|
||
3
|
||
using F = function<bool(const Edge&, const Edge&)>;
|
||
priority_queue<Edge, vector<Edge>, 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; // 小根堆
|
||
}
|
||
//一定是<,不能是>
|
||
} |