1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
| void dijkstra(int s) {
q.push({0, s});
memset(dis, 0x3f, sizeof(dis));
dis[s] = 0;
while (!q.empty()) {
pair<ll, int> p = q.top();
q.pop();
int u = p.second;
ll ww = p.first;
if (dis[u] < ww) continue;
for (int i = 0; i < g[u].size(); i++) {
int v = g[u][i];
if (dis[v] > dis[u] + w[u][i]) {
dis[v] = dis[u] + w[u][i];
q.push({dis[v], v});
}
}
}
}
|