JAVA | PriorityQueue | 100% faster
\tclass Solution {\n\t\tpublic int minCost(int maxTime, int[][] edges, int[] Fees) {\n\n\t\t\tint target=Fees.length-1;\n\t\t\tint[] visited=new int[Fees.length
\tclass Solution {\n\t\tpublic int minCost(int maxTime, int[][] edges, int[] Fees) {\n\n\t\t\tint target=Fees.length-1;\n\t\t\tint[] visited=new int[Fees.length];\n\t\t\tArrays.fill(visited,-1);\n\t\t\tMap<Integer,List<int[]>> map=new HashMap<>();\n\n\t\t\tfor(int[] x: edges){\n\t\t\t\tint u=x[0];\n\t\t\t\tint v=x[1];\n\t\t\t\tint time=x[2];\n\n\t\t\t\tmap.putIfAbsent(u,new ArrayList<>());\n\t\t\t\tmap.putIfAbsent(v,new ArrayList<>());\n\t\t\t\tmap.get(u).add(new int[]{v,time});\n\t\t\t\tmap.get(v).add(new int[]{u,time});\n\t\t\t}\n\n\t\t\tPriorityQueue<int[]> queue=new PriorityQueue<>((a,b)->a[1]==b[1] ? a[2]-b[2] : a[1]-b[1]);\n\t\t\tqueue.add(new int[]{0,Fees[0],0});\n\t\t\tvisited[0]=0;\n\t\t\twhile(!queue.isEmpty()){\n\t\t\t\tint[] curr=queue.poll();\n\t\t\t\tint u=curr[0];\n\t\t\t\tint cost=curr[1];\n\t\t\t\tint time=curr[2];\n\t\t\t\tif(u==target)\n\t\t\t\t\t return cost;\n\t\t\t\tfor(int next[] : map.get(u)){\n\t\t\t\t\tint v=next[0];\n\t\t\t\t\tif(visited[v]!=-1 && time+next[1]>=visited[v])\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\tvisited[v]=time+next[1];\n\t\t\t\t\tif(time+next[1]<=maxTime){\n\t\t\t\t\t\tqueue.add(new int[]{v,cost+Fees[v],time+next[1]});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn -1;\n\t\t}\n\t}
['Heap (Priority Queue)', 'Java']