ps | |
---|---|
링크 | acmicpc.net/… |
출처 | BOJ |
문제 번호 | 1753 |
문제명 | 최단경로 |
레벨 | 골드 5 |
분류 |
그래프, 최단경로 |
시간복잡도 | O(ElogV) |
인풋사이즈 | V<=20,000, E<=300,000 |
사용한 언어 | Python |
제출기록 | 60344KB / 744ms |
최고기록 | 532ms |
해결날짜 | 2021/01/28 |
"""Solution code for "BOJ 1753. 최단경로".
- Problem link: https://www.acmicpc.net/problem/1753
- Solution link: http://www.teferi.net/ps/problems/boj/1753
Tags: [Dijkstra]
"""
import sys
from teflib import graph as tgraph
INF = float('inf')
def main():
V, E = [int(x) for x in sys.stdin.readline().split()]
wgraph = [{} for _ in range(V)]
K = int(sys.stdin.readline())
for _ in range(E):
u, v, w = [int(x) for x in sys.stdin.readline().split()]
if w < (e := wgraph[u - 1]).get(v - 1, INF):
e[v - 1] = w
dists = tgraph.dijkstra(wgraph, K - 1)
print(*('INF' if dist == INF else dist for dist in dists), sep='\n')
if __name__ == '__main__':
main()