Java || Dijkstra || faster than 90.46% || less memo than 95.41%
\nclass Solution {\n    public int minCost(int maxTime, int[][] edges, int[] passingFees) {\n        int n = passingFees.length;\n        List<int[]>[] graph = 
```\nclass Solution {\n    public int minCost(int maxTime, int[][] edges, int[] passingFees) {\n        int n = passingFees.length;\n        List<int[]>[] graph = buildGraph(n, edges);\n\t\t// priority queue makes sure we are polling lowest fee every time\n        PriorityQueue<Node> q = new PriorityQueue<>((a, b) -> Integer.compare(a.fee, b.fee));\n\t\t// The visited records the minimum time to reach that node\n        int[] visited = new int[n];\n        Arrays.fill(visited, Integer.MAX_VALUE);\n        q.offer(new Node(passingFees[0], 0, 0));\n        while (!q.isEmpty()) {\n            Node c = q.poll();\n            if (c.city == n - 1) return c.fee;          \n            for (int[] neighbor: graph[c.city]) {\n                if (c.time + neighbor[1] > maxTime) continue;\n                int newTime = c.time + neighbor[1];\n\t\t\t\t// only if new time to reach the node becomes smaller we have better chance to reach destination\n                if (newTime < visited[neighbor[0]]) {\n                    visited[neighbor[0]] = newTime;\n                    q.offer(new Node(passingFees[neighbor[0]] + c.fee, c.time + neighbor[1], neighbor[0]));\n                }                \n            }\n        }\n        return -1;\n    }\n    private List<int[]>[] buildGraph(int n, int[][] edges) {\n        List<int[]>[] graph = new List[n];\n        Arrays.setAll(graph, r -> new ArrayList<>());\n        for (int[] edge: edges) {\n            int from = edge[0];\n            int to = edge[1];\n            int time = edge[2];\n            graph[from].add(new int[] { to, time });\n            graph[to].add(new int[] { from, time });\n        }\n        return graph;\n    }\n    private static class Node {\n        int fee;\n        int time;\n        int city;\n        public Node(int fee, int time, int city) {\n            this.fee = fee;\n            this.time = time;\n            this.city = city;\n        }\n    }\n}\n```
['Java']