結果
| 問題 |
No.160 最短経路のうち辞書順最小
|
| コンテスト | |
| ユーザー |
tnodino
|
| 提出日時 | 2022-07-24 19:43:29 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 657 bytes |
| コンパイル時間 | 89 ms |
| コンパイル使用メモリ | 12,800 KB |
| 実行使用メモリ | 14,336 KB |
| 最終ジャッジ日時 | 2024-07-06 14:41:16 |
| 合計ジャッジ時間 | 2,431 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 8 WA * 18 |
ソースコード
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])
tnodino