Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

Commit

Permalink
leetcode: finished #743
Browse files Browse the repository at this point in the history
  • Loading branch information
xqm32 committed Feb 2, 2024
1 parent a247d6d commit 4ea8541
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions content/leetcode/2024/2.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,41 @@ title: 2024.2
draft: false
---

# 2024.2.2

```python
#
# @lc app=leetcode.cn id=743 lang=python3
#
# [743] 网络延迟时间
#

# @lc code=start
class Solution:
def networkDelayTime(self, times: List[List[int]], n: int, k: int) -> int:
import heapq

graph = [[] for _ in range(n + 1)]
for u, v, w in times:
graph[u].append((v, w))
dist = [float("inf")] * (n + 1)
dist[k] = 0
heap = [(0, k)]
while heap:
d, u = heapq.heappop(heap)
if d > dist[u]:
continue
for v, w in graph[u]:
if dist[v] > d + w:
dist[v] = d + w
heapq.heappush(heap, (dist[v], v))
res = max(dist[1:])
return res if res < float("inf") else -1


# @lc code=end
```

# 2024.2.1

```python
Expand Down

0 comments on commit 4ea8541

Please sign in to comment.