Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

14-wnsmir #56

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions wnsmir/μ΅œλ‹¨κ²½λ‘œ/전보.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import heapq
import sys

input = sys.stdin.readline
INF = 987654321

N, M ,start = map(int, input().split())
graph = [[]for i in range(N+1)]
distance = [INF]*(N+1)

for _ in range(M+1):
X, Y, Z = map(int, input().split())
graph[X].append(Y, Z)

def dijkstra(start):
q = []
heapq.heappush(q, (0,start))
distance[start] = 0
while q:
dist, now = heapq.heappop(q)
if distance[now] < dist:
continue
for i in graph[now]:
cost = dist + i[1]
if cost < distance[i[0]]:
distance[i[0]] = cost
heapq.heappush(q, (cost,i[0]))
Comment on lines +15 to +27
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

κ°€μ€‘μΉ˜ κ·Έλž˜ν”„μ—μ„œ λ‹€μ΅μŠ€νŠΈλΌλ₯Ό κ΅¬ν˜„ν•˜λŠ” κΈ°λ³Έ 둜직인 것 κ°™λ„€μš”!
직접 κ΅¬ν˜„ν•΄λ³Έ 것은 처음인데, λ‚˜λ¦„ μ§κ΄€μ μœΌλ‘œ 이해가 잘 λμŠ΅λ‹ˆλ‹€.
μ•žμœΌλ‘œλŠ” μ’€ 더 μ–΄λ €μš΄ λ‹€μ΅μŠ€νŠΈλΌλ„ λ§ˆμ£Όν•΄λ³΄κ³  μ‹ΆμŠ΅λ‹ˆλ‹·. πŸ‘


dijkstra(start)

count = 0
max_distance = 0

for d in distance:
if d != INF:
count += 1
max_distance = max(max_distance, d)

print(count -1, max_distance)