Files
lynchmark/tests/1_dijkstra/outputs/anthropic_claude-opus-4.8 EFF_medium.js
2026-05-31 18:07:47 +00:00

24 lines
783 B
JavaScript

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