链式前向星
struct Edge {int to;int next;
}e[maxn];int tot;
int head[maxn];void Add (int u, int v) {e[++ tot].to = v;e[tot].next = head[u];head[u] = tot;
}
快速幂
inline int qpow (int a, int b) {int ans = 1, base = a;while (b > 0) {if (b & 1) ans *= base;base *= base;b >>= 1;}return ans;
}
dijkstra
int n, m, s, d[N];
struct edge {int v, w;
};
vector <edge> g[N];
priority_queue< pair<int, int> > q;void dijkstra(int s) {for (int i = 1; i <= n; i ++) d[i] = inf;d[s] = 0;q.push({0, s});while (!q.empty()) {auto t = q.top();q.pop();int u = t.second;for (auto ed : g[u]) {int v = ed.v, w = ed.w;if (d[v] > d[u] + w) {d[v] = d[u] + w;q.push({-d[v], v});}}}
}
Floyed
for (int k = 1; k <= n; k ++)for (int i = 1; i <= n; i ++)for (int j = 1; j <= n; j ++)f[i][j] = min(f[i][j], f[i][k] + f[k][j]);
施工中......