You are viewing a single comment's thread. Return to all comments →
JS
function getCost(gNodes, gFrom, gTo, gWeight) { const edges = gWeight.map((w, i) => [[gFrom[i], gTo[i], w], [gTo[i], gFrom[i], w]]).flat() const costs = [true, 0, ...Array(gNodes - 1).fill(Infinity)] while (costs[0] && !(costs[0] = false)) for (const [x, y, w] of edges) if (costs[y] > costs[x] && costs[y] > w) costs[0] = !!(costs[y] = Math.max(costs[x], w)) console.log(costs[gNodes] !== Infinity ? costs[gNodes] : 'NO PATH EXISTS') }
Seems like cookies are disabled on this browser, please enable them to open this website
Jack goes to Rapture
You are viewing a single comment's thread. Return to all comments →
JS