Dijkstra's Algorithms
Dijkstra\'s Algorithm\n\nclass Solution:\n    def networkDelayTime(self, times: List[List[int]], n: int, k: int) -> int:\n        edges=defaultdict(list)\n     
# Dijkstra\'s Algorithm\n```\nclass Solution:\n    def networkDelayTime(self, times: List[List[int]], n: int, k: int) -> int:\n        edges=defaultdict(list)\n        for u, v, w in times:\n            #graph[u-1].append((v-1, w))\n            edges[u].append((v,w))\n        minheap=[(0,k)]\n        visit=set()\n        t=0\n        while minheap:\n            w1,n1=heapq.heappop(minheap)\n            if n1 in visit:\n                continue\n            visit.add(n1)\n            t=max(t,w1)\n            for n2,w2 in edges[n1]:\n                if n2 not in visit:\n                    heapq.heappush(minheap,((w1+w2),n2))\n        return t if len(visit)==n else -1\n```\n# please upvote me it would encourage me alot\n
['Python3']