NewCodeTemplate

This commit is contained in:
e2hang
2025-12-16 20:36:27 +08:00
parent 684e35b210
commit 8253f2dcbc
26 changed files with 2547 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
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; // 小根堆
}
//一定是<,不能是>
}