int ecnt = 2; // 这也是黑魔法,直接0就行了 int n, m, k, s, t; int head[150005], dis[150005], vis[150005]; structedge {int to, next, w; } g[300010]; voidadd_edge(int u, int v, int w){ g[ecnt] = (edge) { v, head[u], w }; head[u] = ecnt ++; }
voiddijkstra(){ for (int i = 0; i <= n; i ++) dis[i] = 8e18; dis[s] = 0; q.push((node) { dis[s], s }); while (!q.empty()) { int u = q.top().pos; q.pop(); if (vis[u]) continue; vis[u] = true; for (int e = head[u]; e; e = g[e].next) { int v = g[e].to; // 图论基本方程 if (dis[v] > dis[u] + g[e].w) { dis[v] = dis[u] + g[e].w; q.push((node) { dis[v], v }); } } } }