2
record Node(int i, int t) {}4
record Cell(int i, int t, int c) {}6
public int minCost(int maxTime, int[][] edges, int[] fees) {9
// create the adjacency list graph10
List<Node>[] g = new List[n];11
for (int i = 0; i < n; i++) g[i] = new ArrayList<>();13
g[e[0]].add(new Node(e[1], e[2]));14
g[e[1]].add(new Node(e[0], e[2]));18
Queue<Cell> q = new PriorityQueue<>((a, b) -> a.c == b.c ? a.t - b.t : a.c - b.c);19
int[] T = new int[n]; // 1. visited: de-dup 2. de-dup on worst time21
q.offer(new Cell(0, 0, fees[0]));22
Arrays.fill(T, maxTime + 1);25
while (!q.isEmpty()) {27
if (cur.i == n - 1) return cur.c;29
for (var nei : g[cur.i]) {30
int t2 = cur.t + nei.t;31
if (t2 >= T[nei.i]) continue; // if time is worst, no reason to continue33
q.offer(new Cell(nei.i, t2, cur.c + fees[nei.i]));