restructure zeta/** to storage/zeta/**

This commit is contained in:
2025-05-10 21:54:24 +09:00
parent 2886820691
commit 2f2e0759fd
407 changed files with 7 additions and 1 deletions

View File

@@ -0,0 +1,46 @@
import sys
import heapq as hq
input = sys.stdin.readline
def solve(V, E, K) -> list[int]:
W = [1 << 31 for _ in range(V + 1)]
W[K] = 0
D = []
hq.heappush(D, (W[K], K))
while D:
d, k = hq.heappop(D)
if d > W[k]:
continue
for v, w in E[k]:
nd = d + w
if W[v] > nd:
W[v] = nd
hq.heappush(D, (nd, v))
return W
def pformat(x):
if x >= 1 << 31:
return 'INF'
else:
return x
if __name__ == '__main__':
V, n = map(int, input().split())
K = int(input())
E = {}
for i in range(1, V + 1):
E[i] = []
for _ in range(n):
u, v, w = map(int, input().split())
E[u].append((v, w))
[print(pformat(i)) for i in solve(V, E, K)[1:]]