bool check(int bound)
{
memset(dist, 0x3f, sizeof dist);
memset(st, 0, sizeof st);
q.push_back(1);
dist[1] = 0;
while (q.size())
{
int t = q.front();
q.pop_front();
if (st[t]) continue;
st[t] = true;
for (int i = h[t]; ~i; i = ne[i])
{
int j = e[i];
if (dist[j] > dist[t] + w[i])
{
dist[j] = dist[t] + w[i];
if (!w[i]) q.push_front(j);//根据边权是0/1插入队头或队尾
else q.push_back(j);
}
}
}
}
双端队列求最短路模板
最新推荐文章于 2021-09-03 20:16:41 发布