【Dijkstra】
class Solution {
public double maxProbability(int n, int[][] edges, double[] succProb, int start, int end) {
List<double[]>[] lists = new List[n];
for(var i = 0; i < n; i++) lists[i] = new ArrayList<double[]>();
int m = edges.length;
for(var i = 0; i < m; i++){
lists[edges[i][0]].add(new double[] {edges[i][1], succProb[i]});
lists[edges[i][1]].add(new double[] {edges[i][0], succProb[i]});
}
double[] dis = new double[n];
Arrays.fill(dis, -1);
dis[start] = 1;
PriorityQueue<double[]> queue = new PriorityQueue<double[]>((a, b) -> { return a[1] > b[1] ? -1: 1;});
queue.offer(new double[] {start, 1});
while(!queue.isEmpty()){
double[] top = queue.poll();
double d = top[1];
int x = (int)top[0];
if(x == end) return d;
for(var arr: lists[x]){
int y = (int)arr[0];
if(dis[y] == -1 || d * arr[1] > dis[y]){
dis[y] = d * arr[1];
queue.offer(new double[] {y, dis[y]});
}
}
}
return dis[end] == -1 ? 0: dis[end];
}
}