const int INF = 1000000000;
int N, D, C;
vector<pii> graph[10002];
int dist[10002];
int a, b, c;
vector <int> path[10002];
priority_queue <pair<int, int>> pq;
for (int i = 1; i <= N; i++)
dist[i] = INF;
priority_queue<pair<int, int>> pq;
pq.push({ 0, C });
dist[C] = 0;
while (!pq.empty())
{
int cost = -pq.top().first;
int cur = pq.top().second;
pq.pop();
if (dist[cur] < cost)
continue;
for (int j = 0; j < graph[cur].size(); j++)
{
int next = graph[cur][j].first;
int nCost = graph[cur][j].second;
if (dist[next] > cost + nCost)
{
dist[next] = cost + nCost;
pq.push(make_pair(-dist[next], next));
}
}
}
'알고리즘 > 알고리즘 이론, 템플릿' 카테고리의 다른 글
머지소트트리 (0) | 2024.03.03 |
---|---|
LCA , sparsetable (0) | 2023.12.11 |
포함배제원리와 뫼비우스함수 (0) | 2023.09.20 |
모듈러 역원와 페르마의 소정리 (0) | 2023.09.12 |
레이지세그 (0) | 2023.08.21 |