在写 Dijkstra 的时候,我习惯使用 struct 而非 pair<int, int>,查阅资料发现若需要实现优先队列小根堆的时候需要这么重载
struct _node {
int v, w;
bool operator < (const _node b) const {
return w > b.w;
}
};
而非
struct _node {
int v, w;
bool operator < (const _node b) const {
return w < b.w;
}
};
有点反直觉,有人知道为什么这么写吗