1
var maxProbability = function (n, edges, succProb, start, end) {2
const graph = new Map();3
edges.forEach(([a, b], i) => {4
const aSet = graph.get(a) || [];5
const bSet = graph.get(b) || [];6
aSet.push([b, succProb[i]]), bSet.push([a, succProb[i]]);7
graph.set(a, aSet), graph.set(b, bSet);10
const dist = new Array(n).fill(0);11
const vis = new Array(n).fill(false);15
const getMaxProbNode = () => {18
for (let i = 0; i < n; i++) {19
if (maxVal < dist[i] && !vis[i]) {20
(maxVal = dist[i]), (maxIndex = i);26
for (let i = 0; i < n - 1; i++) {27
const maxProbNode = getMaxProbNode();28
vis[maxProbNode] = true;30
const adjacentNodes = graph.get(maxProbNode) || [];31
const len = adjacentNodes.length;32
for (let j = 0; j < len; j++) {33
const [node, prob] = adjacentNodes[j];34
if (!vis[node] && dist[node] < dist[maxProbNode] * prob) {35
dist[node] = dist[maxProbNode] * prob;