Skip to content

Commit

Permalink
34-alstjr7437 (#241)
Browse files Browse the repository at this point in the history
  • Loading branch information
alstjr7437 authored Sep 27, 2024
1 parent 9db5604 commit 8e74983
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
3 changes: 2 additions & 1 deletion alstjr7437/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@
| 30์ฐจ์‹œ | 2024.06.19 | ๊ตฌํ˜„ | <a href="https://www.acmicpc.net/problem/1475">๋ฐฉ ๋ฒˆํ˜ธ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/211 |
| 31์ฐจ์‹œ | 2024.06.19 | BFS | <a href="https://school.programmers.co.kr/learn/courses/30/lessons/1844">๊ฒŒ์ž„ ๋งต ์ตœ๋‹จ๊ฑฐ๋ฆฌ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/218 |
| 32์ฐจ์‹œ | 2024.08.15 | ํˆฌ ํฌ์ธํ„ฐ | <a href="https://www.acmicpc.net/problem/30804">๊ณผ์ผ ํƒ•ํ›„๋ฃจ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/230 |
| 33์ฐจ์‹œ | 2024.08.21 | BFS | <a href="https://www.acmicpc.net/problem/9019">DSLR</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/236 |
| 33์ฐจ์‹œ | 2024.08.21 | BFS | <a href="https://www.acmicpc.net/problem/9019">DSLR</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/236 |
| 34์ฐจ์‹œ | 2024.08.28 | ๋‹ค์ต์ŠคํŠธ๋ผ | <a href="https://www.acmicpc.net/problem/1238">ํŒŒํ‹ฐ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/241 |
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from collections import deque
import sys

input = sys.stdin.readline
INF = int(1e9)

N, M, X = map(int, input().split())

graph = [[] for _ in range(N+1)]

for _ in range(M):
start, target, dist = map(int, input().split())
graph[start].append((target, dist))

def dijkstra(root):
queue = deque()
distance = [INF] * (N + 1)

distance[root] = 0
queue.append((root, 0))
while queue:
now, dist = queue.popleft()

for target, cost in graph[now]:
target_cost = dist + cost

if distance[target] > target_cost:
distance[target] = target_cost
queue.append((target, target_cost))
return distance

result = []
for i in range(1, N+1):
go = dijkstra(i)[X]
back = dijkstra(X)[i]
result.append(go+back)

print(max(result))

0 comments on commit 8e74983

Please sign in to comment.