Java Solution | Using DP
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: $$O(maxTime * edges.length)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(maxTime * passingFees.length)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public int minCost(int maxTime, int[][] edges, int[] passingFees) {\n        int dp[][] = new int[maxTime+1][passingFees.length];\n\n        for (int i=0; i<=maxTime; i++) {\n            for(int j=0; j<passingFees.length; j++) {\n                dp[i][j] = Integer.MAX_VALUE;\n            }\n        }\n\n        dp[0][0] = passingFees[0];\n        \n        int reachTime = 0;\n        int city1, city2;\n\n        for (int i=0; i<=maxTime; i++) {\n            for (int j=0; j<edges.length; j++) {\n                reachTime = i+edges[j][2];\n                city1 = edges[j][0];\n                city2 = edges[j][1];\n\n                if (reachTime <= maxTime) {\n                    if (dp[i][city1] != Integer.MAX_VALUE) dp[reachTime][city2] = Math.min(dp[reachTime][city2], dp[i][city1] + passingFees[city2]);\n                    if (dp[i][city2] != Integer.MAX_VALUE) dp[reachTime][city1] = Math.min(dp[reachTime][city1], dp[i][city2] + passingFees[city1]);\n                }\n            }\n        }\n\n        int res = Integer.MAX_VALUE;\n        for (int i=0; i<=maxTime; i++) res = Math.min(res, dp[i][passingFees.length-1]);\n\n        return (res != Integer.MAX_VALUE) ? res : -1;\n    }\n}\n```
['Dynamic Programming', 'Graph', 'Java']