Files
lynchmark/tests/1_dijkstra/outputs/google_gemini-3-pro-preview.js
2025-11-18 17:37:06 +00:00

19 lines
549 B
JavaScript

const findShortestPath = async (g, s, e) => {
const { default: P } = await import('https://cdn.skypack.dev/js-priority-queue')
const d = { [s]: 0 }, q = new P({ comparator: (a, b) => a.w - b.w })
q.queue({ w: 0, n: s })
while (q.length) {
const { w, n } = q.dequeue()
if (n === e) return w
if (w > (d[n] ?? 1 / 0)) continue
for (const v in g[n]) {
const t = w + g[n][v]
if (t < (d[v] ?? 1 / 0)) {
d[v] = t
q.queue({ w: t, n: v })
}
}
}
return 1 / 0
}
export default findShortestPath;