AcWing 844. 走迷宫
原题链接
简单
作者:
nwpu
,
2024-03-02 01:40:33
,
所有人可见
,
阅读 24
#include <queue>
// 点优先队列
typedef pair<int,int> PII;
queue<PII> q;
PII p = q.front();
q.pop();
q.empty();
q.push({0, 0});
// visited[][]标记
int vt[N][M];
// path标记
int path[N * M];
// if q.pop() => {a, b}, then q.push({c, d}) => from {a,b} to {c,d}
path[(c * M + d)] = a * M + b; // cur => prev
// bfs基本操作
q.push(init);
while (!q.empty()) {
cur = q.front();
q.pop();
[next] = get_next(cur) if !vt[next];
for (n : next) {
path[cur] = n;
q.push(n);
}
}