Max-heap Dijkstra
Time O(E log V) Space O(V + E)prob[start] = 1. Pop the largest probability; relax neighbours with prob × p.
import java.util.*;
class Solution {
public double maxProbability(int n, int[][] edges, double[] succProb, int start, int end) {
List<List<double[]>> adj = new ArrayList<>();
for (int i = 0; i < n; i++) adj.add(new ArrayList<>());
for (int i = 0; i < edges.length; i++) {
adj.get(edges[i][0]).add(new double[]{edges[i][1], succProb[i]});
adj.get(edges[i][1]).add(new double[]{edges[i][0], succProb[i]});
}
double[] best = new double[n];
best[start] = 1.0;
PriorityQueue<double[]> pq = new PriorityQueue<>((a, b) -> Double.compare(b[0], a[0]));
pq.offer(new double[]{1.0, start});
while (!pq.isEmpty()) {
double[] t = pq.poll();
int u = (int) t[1];
if (u == end) return t[0];
if (t[0] < best[u]) continue;
for (double[] e : adj.get(u)) {
int v = (int) e[0];
double p = t[0] * e[1];
if (p > best[v]) { best[v] = p; pq.offer(new double[]{p, v}); }
}
}
return 0.0;
}
}Verdict: Same algorithm, flipped comparison.