結果
問題 | No.160 最短経路のうち辞書順最小 |
ユーザー | tnodino |
提出日時 | 2022-07-24 19:43:29 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 657 bytes |
コンパイル時間 | 69 ms |
コンパイル使用メモリ | 10,772 KB |
実行使用メモリ | 11,900 KB |
最終ジャッジ日時 | 2023-09-20 19:44:49 |
合計ジャッジ時間 | 2,504 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 19 ms
8,640 KB |
testcase_01 | AC | 19 ms
8,520 KB |
testcase_02 | AC | 18 ms
8,688 KB |
testcase_03 | AC | 18 ms
8,676 KB |
testcase_04 | AC | 43 ms
9,416 KB |
testcase_05 | AC | 70 ms
10,072 KB |
testcase_06 | AC | 102 ms
10,608 KB |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | AC | 29 ms
8,908 KB |
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 | AC | 28 ms
8,880 KB |
testcase_20 | AC | 29 ms
8,944 KB |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | AC | 20 ms
8,592 KB |
testcase_28 | WA | - |
testcase_29 | AC | 20 ms
8,632 KB |
ソースコード
from collections import deque INF = 1<<64 N,M,S,T = map(int,input().split()) G = [[] for _ in range(N)] for _ in range(M): a,b,c = map(int,input().split()) G[a].append((b, c)) G[b].append((a, c)) for i in range(N): G[i].sort() cost = [INF] * N cost[S] = 0 Queue = deque() Queue.append(S) while Queue: pos = Queue.popleft() for nxt,c in G[pos]: if cost[pos] + c < cost[nxt]: cost[nxt] = cost[pos] + c Queue.append(nxt) pos = T ans = [T] while pos != S: for nxt,c in G[pos]: if cost[pos] - c == cost[nxt]: ans.append(nxt) pos = nxt break print(*ans[::-1])