JAVA SIMPLE SOLUTION runtime:- 56ms
\nclass Solution {\n    public int minCost(int maxTime, int[][] edges, int[] passingFees) {\n        ArrayList<ArrayList<road>> country= new ArrayList<ArrayList
```\nclass Solution {\n    public int minCost(int maxTime, int[][] edges, int[] passingFees) {\n        ArrayList<ArrayList<road>> country= new ArrayList<ArrayList<road>>();\n        int l=passingFees.length;\n        for(int i=0;i<l;i++)\n        {\n            country.add(new ArrayList<road>());\n        }\n        for(int i=0;i<edges.length;i++)\n        {\n            country.get(edges[i][0]).add(new road(edges[i][1],edges[i][2]));\n            country.get(edges[i][1]).add(new road(edges[i][0],edges[i][2]));\n        }\n        return smartdrive(maxTime,0,l-1,passingFees,country);\n    }\n    public int smartdrive(int maxTime, int s, int e, int []fees, ArrayList<ArrayList<road>> country)\n    {\n        PriorityQueue<costpriority> order= new PriorityQueue<costpriority>(new prioritycomparator());\n        order.offer( new costpriority(fees[s],s,0));\n        int []cost= new int[fees.length];\n        int []time= new int[fees.length];\n        Arrays.fill(cost,Integer.MAX_VALUE);\n        Arrays.fill(time,Integer.MAX_VALUE);\n        cost[s]=fees[s];\n        time[s]=0;\n        while(order.size()>0)\n        {\n            costpriority top=order.poll();\n            int c=top.cost;\n            int x=top.city;\n            int t=top.time;\n            if(t>maxTime)\n                continue;\n            if(x==e)\n                return c;\n            for(road i:country.get(x))\n            {\n                if(fees[i.city]+c<cost[i.city])\n                {\n                    cost[i.city]=fees[i.city]+c;\n                    time[i.city]=i.time+t;\n                    order.offer(new costpriority(cost[i.city],i.city,time[i.city]));\n                }\n                if(i.time+t<time[i.city])\n                {\n                    time[i.city]=i.time+t;\n                    order.offer(new costpriority(fees[i.city]+c,i.city,time[i.city]));\n                }\n            }\n        }\n        return -1;\n    }\n    class road{\n        int city;\n        int time;\n        road(int city,int time)\n        {\n            this.city=city;\n            this.time=time;\n        }\n    }\n    class prioritycomparator implements Comparator<costpriority>{\n        public int compare(costpriority a, costpriority b)\n        {\n            return a.cost-b.cost;\n        }\n    }\n    class costpriority{\n        int cost;\n        int city;\n        int time;\n        costpriority(int cost, int city, int time)\n        {\n            this.cost=cost;\n            this.city=city;\n            this.time=time;\n        }\n        \n    }\n}\n```
['Heap (Priority Queue)']