結果

問題 No.160 最短経路のうち辞書順最小
ユーザー ckawatakckawatak
提出日時 2017-10-24 15:33:40
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 788 bytes
コンパイル時間 310 ms
コンパイル使用メモリ 82,136 KB
実行使用メモリ 80,480 KB
最終ジャッジ日時 2024-05-01 13:06:31
合計ジャッジ時間 5,346 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 62 ms
67,204 KB
testcase_01 AC 61 ms
68,720 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 126 ms
79,624 KB
testcase_29 AC 95 ms
79,180 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from queue import PriorityQueue

N,M,S,G = list(map(int, input().split(' ')))

T = []
for i in range(N):
    T.append([-1 for _ in range(N)])

for i in range(M):
    b,e,t = list(map(int, input().split(' ')))
    T[b][e] = t
    T[e][b] = t

D = []
for i in range(N):
    D.append(float('inf'))
D[S] = 0

P = []
for i in range(N):
    P.append(-1)

Q = PriorityQueue()
for i, d in enumerate(D):
    Q.put((d, i))

while not Q.empty():
    d, u = Q.get()
    for v, t in enumerate(T[u]):
        if t != -1:
            s = D[u] + t
            if s < D[v]:
                D[v] = s
                P[v] = u
                Q.put((s, v))

R = {}
for i, d in enumerate(D):
    R[d] = i

solution = []
for r in sorted(R.keys()):
    solution.append(str(R[r]))
    
print(' '.join(solution))
0