Optimized and cleaned Swift conversion of the most popular C++ solution
Intuition\n\nI had trouble figuring out how to store the most optimal route while at the same time ensuring we\'re not timing out. Normal Dijkstra applications 
# Intuition\n\nI had trouble figuring out how to store the most optimal route while at the same time ensuring we\'re not timing out. Normal Dijkstra applications have only one score.\n\n# Approach\n\nSince I tanked this one myself I tried to find a Swift solution first, which didn\'t exist, then in different langauges. There were actually a few that didn\'t make it to the end either, so I guess I was not the only one struggling.\n\nI used the following (currently most popular) answer written in C++ and converted it automatically to Swift:\nhttps://leetcode.com/problems/minimum-cost-to-reach-destination-in-time/solutions/1328953/c-solution-dijkstra-s-algorithm/\n\nThis passed the test, and judging by the numbers, also as the first Swift user.\n\nHowever the solution was not super readable and it also seemed to take some unnecessary steps. I cleaned it up and it performed about 10% faster than the original conversion I had before\n\n# Complexity\n\nTime complexity:\nO(V*Vlog V) according to the author\n\n# Code\n```\nstruct PathInfo {\n    let cost: Int\n    let time: Int\n    let city: Int\n}\n\nstruct Edge {\n    let destination: Int\n    let travelTime: Int\n    let fee: Int\n}\n\nclass Solution {\n    var adjacencyList = [[Edge]](repeating: [], count: 1001)\n    var cost = [Int](repeating: Int.max, count: 1001)\n    var time = [Int](repeating: Int.max, count: 1001)\n\n    func dijkstra(source: Int, destination: Int, maxTime: Int) -> Int {\n        var priorityQueue = [PathInfo]()\n        priorityQueue.append(PathInfo(cost: cost[source], time: 0, city: source))\n\n        while !priorityQueue.isEmpty {\n            let currentPath = priorityQueue.removeFirst()\n\n            for edge in adjacencyList[currentPath.city] {\n                let newTime = currentPath.time + edge.travelTime\n\n                if newTime <= maxTime {\n                    let totalCost = currentPath.cost + edge.fee\n\n                    if cost[edge.destination] > totalCost {\n                        cost[edge.destination] = totalCost\n                    } else if time[edge.destination] <= newTime {\n                        continue\n                    }\n\n                    time[edge.destination] = newTime\n\n                    priorityQueue.append(PathInfo(cost: totalCost, time: newTime, city: edge.destination))\n                }\n            }\n            \n            priorityQueue.sort { $0.cost < $1.cost }\n        }\n\n        return cost[destination]\n    }\n\n    func minCost(_ maxTime: Int, _ edges: [[Int]], _ passingFees: [Int]) -> Int {\n        for edge in edges {\n            let city1 = edge[0]\n            let city2 = edge[1]\n            let travelTime = edge[2]\n\n            adjacencyList[city1].append(Edge(destination: city2, travelTime: travelTime, fee: passingFees[city2]))\n            adjacencyList[city2].append(Edge(destination: city1, travelTime: travelTime, fee: passingFees[city1]))\n        }\n\n        cost[0] = passingFees[0]\n        time[0] = 0\n\n        let answer = dijkstra(source: 0, destination: passingFees.count - 1, maxTime: maxTime)\n        return answer == Int.max ? -1 : answer\n    }\n}\n```
['Swift']