Skip to content

Commit

Permalink
feat : 북쪽나라의 도로 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
jeeminimini committed Nov 20, 2023
1 parent ce6a267 commit 18960f4
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/main/kotlin/jimin/50week/북쪽나라의 도로.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
'''
https://dodobow.tistory.com/35
근데 왜 1과 1로 돌고 난 후의 max만 확인하면 될까?
'''

import sys
from collections import deque

roads = [[] for _ in range(10_001)]
while True:
try:
a, b, c = map(int, sys.stdin.readline().split())
roads[a].append([b, c])
roads[b].append([a, c])
except:
break


def bfs(start):
queue = deque([start])

visited[start] = 0

while queue:
now = queue.popleft()

for i, w in roads[now]:
if visited[i] == -1:
visited[i] = visited[now] + w
queue.append(i)


visited = [-1 for _ in range(10_001)]
bfs(1)
s = visited.index(max(visited))
visited = [-1 for _ in range(10_001)]
bfs(s)
print(max(visited))

0 comments on commit 18960f4

Please sign in to comment.