Files
lynchmark/tests/1_dijkstra/outputs/google_gemini-3.8-flash EFF_high.js
2026-09-08 14:30:30 +00:00

27 lines
798 B
JavaScript

export async function findShortestPath(graph, start, end) {
const { default: PriorityQueue } = await import('https://esm.sh/js-priority-queue');
const dist = new Map([[start, 0]]);
const pq = new PriorityQueue({ comparator: (a, b) => a[1] - b[1] });
pq.queue([start, 0]);
while (pq.length) {
const [node, cost] = pq.dequeue();
if (node === end) return cost;
if (cost > (dist.get(node) ?? Infinity)) continue;
for (const [neighbor, weight] of Object.entries(graph[node] ?? {})) {
const nextCost = cost + weight;
if (nextCost < (dist.get(neighbor) ?? Infinity)) {
dist.set(neighbor, nextCost);
pq.queue([neighbor, nextCost]);
}
}
}
return Infinity;
}
export default findShortestPath;
// Generation time: 16.431s
// Result: PASS