#include <bits/stdc++.h>
using namespace std;
const int INF = numeric_limits::max();
struct Edge {
int to;
int weight;
};
struct Node {
int id;
int dist;
bool operator>(const Node& other) const {
return dist > other.dist;
}
};
map<int, int> dijkstra(const vector>& graph, int n, int source, map<int, int>& prev) {
map<int, int> dist;
for (int i = 0; i < n; ++i) {
dist[i] = INF;
prev[i] = -1;
}
dist[source] = 0;
priority_queue, greater> pq;
pq.push({source, 0});
while (!pq.empty()) {
Node current = pq.top();
pq.pop();
int u = current.id;
int d = current.dist;
if (d > dist[u]) {
continue;
}
for (const Edge& edge : graph[u]) {
int v = edge.to;
int weight = edge.weight;
if (dist[u] != INF && dist[u] + weight < dist[v]) {
dist[v] = dist[u] + weight;
prev[v] = u;
pq.push({v, dist[v]});
}
}
}
return dist;
}