- B1: 前缀和与差分
- B2: 快速组合
- B3: 二分查找
- B4: 高精度加法
- B4: 高精度除法
- B4: 高精度乘法
- B4: 高精度减法
- D1: 单调栈
- D2: 单调队列
- D3: Spare Table
- D4: 字典树
- D5: 并查集
- D6: 树状数组-限定区间计数
- D6: 树状数组-单点更新区间求和
- D7: 线段树-基础
- G1: 二分图-判定
- G2: 二分图-最大匹配
- G3: Astar k短路 on matrix
- G4: 拓扑排序
- G5: 连通无环无向图的重心
- G6: MST-Kruskal
- G7: MST-Prim
- G8: ShortestPath-BellmanFord
- G9: ShortestPath-Dijkstra
- G9: ShortestPath-Dijkstra Heap OPT
- G10: ShortestPath-SPFA
- G11: ShortestPath-Floyd
- M1: 快速幂与龟速乘
- M2: 欧几里得-最大公约数
- M2: EX欧几里得-翡蜀定理
- M2: EX欧几里得-线性同余方程
- M2: EX欧几里得-乘法逆元
- M3: 费马小定理-乘法逆元
- M4: 分解质因数
- M4: 分解质因数-欧拉函数
- M4: 分解质因数-多数乘积约数计数
- M4: 分解质因数-多数乘积约数求和
- M5: 欧拉筛
- M5: 欧拉筛-质数筛
- M6: 埃氏筛-质数筛
- M7: Stein算法-最大公约数
- M8: 矩阵乘法与快速幂
- O1: 快速排序
- O2: 并归排序
- S1: KMP
- S2: 字符串哈希
This doc has been marked needs-review. Following information are in upcoming update plan.
template< class type >
class SPS_Dijkstra {
typedef pair< type, int > pti;
const int n;
bool vis[maxn + 1] {}; // 表示源点到该点的距离还没有(被更新且已经松弛了其出边)的状态.最后被动确定的点不被标记
priority_queue< pti, vector< pti >, greater< pti > > srp; // 距离-节点地址
public:
struct node {
int to, ptr;
type len;
} ar[maxm + 1]; // 链式前向星存图, ar[0]不存, ptr==0视为ptr==null
int head[maxn + 1] {};
const type INF = numeric_limits< type >::max() >> 1u;
type dis[maxn + 1] {}; // 表示源点到该点的最短距离
explicit SPS_Dijkstra(const int n) : n(n) {} // single point shortest path for sparse graph (Dijkstra)
void solve(const int source) {
fill(dis + 1, dis + n + 1, INF);
fill(vis + 1, vis + n + 1, false);
priority_queue< pti, vector< pti >, greater< pti > >().swap(srp);
srp.emplace(dis[source] = 0, source); // 确定源点到源点的最短路,但没有更新其出边,不能在vis中标记源点
while (!srp.empty()) { // 确定源点到vis中最短距离的点->更新其出边->从vis中删除该点,最后一个点被动确定
static int cur;
cur = srp.top().second, srp.pop();
if (vis[cur]) continue; // 在vis中寻找距离源点最近的点
vis[cur] = true;
for (int i = head[cur]; i; i = ar[i].ptr)
if (!vis[ar[i].to]) { // 尝试松弛其出边, 将松弛成功的边的入点放入优先队列(小根堆)
static type dist;
if ((dist = dis[cur] + ar[i].len) < dis[ar[i].to])
srp.emplace(dis[ar[i].to] = dist, ar[i].to);
}
}
}
};