Files
lynchmark/tests/1_dijkstra/outputs/anthropic_claude-opus-4.7 EFF_medium.js
2026-04-17 01:01:24 +00:00

24 lines
743 B
JavaScript

async function findShortestPath(graph, start, end) {
const { default: PriorityQueue } = await import('https://esm.sh/js-priority-queue');
const dist = {};
for (const n in graph) dist[n] = Infinity;
dist[start] = 0;
const pq = new PriorityQueue({ comparator: (a, b) => a[0] - b[0] });
pq.queue([0, start]);
while (pq.length) {
const [d, node] = pq.dequeue();
if (node === end) return d;
if (d > dist[node]) continue;
for (const [next, w] of Object.entries(graph[node] || {})) {
const nd = d + w;
if (nd < (dist[next] ?? Infinity)) {
dist[next] = nd;
pq.queue([nd, next]);
}
}
}
return Infinity;
}
export default findShortestPath;
// Generation time: 4.505s
// Result: PASS