blob: e7ec0c340070e9965067313697266a4e576855ef (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
priority_queue<ii, vector<ii>, greater<ii> > pq;
vector<int> dist;
dist.assign(NUM_VERTICES, INF);
dist[0] = 0;
pq.push(ii(0, 0));
while (!pq.empty()) {
di front = pq.top(); pq.pop();
int curNode = front.second, curDist = front.first;
if (curDist > dist[curNode]) continue;
for (i = 0; i < (int)adjlist[curNode].size(); i++) {
int nextNode = adjlist[curNode][i].first, nextDist = curDist + adjlist[curNode][i].second;
if (nextDist < dist[nextNode]) {
dist[nextNode] = nextDist; pq.push(ii(nextDist, nextNode));
}
}
}
|