[Java] DFS + DP[Memoisation] | Simple Solution
\nclass Solution {\n    class Edge {\n        int src, nbr, wt;\n        public Edge(int src, int nbr, int wt) {\n            this.src = src;\n            this.
```\nclass Solution {\n    class Edge {\n        int src, nbr, wt;\n        public Edge(int src, int nbr, int wt) {\n            this.src = src;\n            this.nbr = nbr;\n            this.wt = wt;\n        }\n    }\n\n    public int minCost(int maxTime, int[][] edges, int[] passingFees) {\n        int n = passingFees.length;\n        List<Edge>[] graph = new ArrayList[n];\n        for(int i = 0; i < n; i++)\n            graph[i] = new ArrayList<>();\n        for(int[] edge : edges){\n            graph[edge[0]].add(new Edge(edge[0], edge[1], edge[2]));\n            graph[edge[1]].add(new Edge(edge[1], edge[0], edge[2]));\n        }\n        return DFS(graph, 0, maxTime, passingFees, new Integer[1001][maxTime + 1]);\n    }\n    \n    private int DFS(List<Edge>[] graph, int src, int remTime, int[] passingFees, Integer[][] dp){\n        if(remTime < 0)\n            return -1;\n        if(dp[src][remTime] != null)\n            return dp[src][remTime];\n        if(src == passingFees.length - 1)\n            return (dp[src][remTime] = passingFees[src]);\n        int min = -1;\n        for(Edge e : graph[src]){\n            int x = DFS(graph, e.nbr, remTime - e.wt, passingFees, dp);\n            if(min == -1)\n                min = x;\n            else if(x != -1)\n                min = Math.min(min, x);\n        }\n        if(min == -1)\n            return (dp[src][remTime] = -1);\n        return (dp[src][remTime] = min + passingFees[src]);\n    }\n}\n```
[]