堆优化的dij为什么不把起点初始为已经访问过了呢qaq?

P4779 【模板】单源最短路径(标准版)

@[LPA20020220](/space/show?uid=67492) 我真的一直不加啊
by 曹老师 @ 2018-10-14 09:26:14


```cpp void dij(int s) { for(int i=1; i<=n; i++) dis[i] = INF; dis[s] = 0; q.push(Road(s,dis[s])); while(!q.empty()) { Road u = q.top(); q.pop(); if(u.len != dis[u.num]) continue; for(int i=head[u.num]; i ; i=e[i].next) { if(e[i].len + u.len < dis[e[i].to]) { dis[e[i].to] = e[i].len + u.len; q.push(Road(e[i].to , dis[e[i].to])); } } } } ```
by 曹老师 @ 2018-10-14 09:27:11


@[LPA20020220](/space/show?uid=67492) ```cpp if(u.len != dis[u.num]) continue; ``` 这一句起到vis的作用了啊
by 曹老师 @ 2018-10-14 09:27:41


vis指的是如果更新过一次就直接在堆里修改, 不再push一次qwq@[曹老师](/space/show?uid=37427)
by LPA20020220 @ 2018-10-14 09:28:51


不然你可能一个点push了很多次, 然后就比较爆炸了
by LPA20020220 @ 2018-10-14 09:29:26


那个hdle数组就是来存在堆中的位置的
by LPA20020220 @ 2018-10-14 09:30:02


可以手写配对堆或者pbds配对堆实现
by LPA20020220 @ 2018-10-14 09:30:36


上一页 |