結果
| 問題 |
No.160 最短経路のうち辞書順最小
|
| コンテスト | |
| ユーザー |
mkawa2
|
| 提出日時 | 2020-01-24 14:58:27 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,129 bytes |
| コンパイル時間 | 104 ms |
| コンパイル使用メモリ | 12,544 KB |
| 実行使用メモリ | 18,048 KB |
| 最終ジャッジ日時 | 2024-09-14 03:41:45 |
| 合計ジャッジ時間 | 2,750 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | WA * 26 |
ソースコード
from heapq import *
from collections import defaultdict
import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]
# 同じ距離のときにルートの辞書順が小さい方を選べばいいので
# キーの2番目にルートを文字列でいれておいてダイクストラ
def main():
n, m, s, g = MI()
to = defaultdict(list)
for _ in range(m):
a, b, c = MI()
to[a].append([b, c])
to[b].append([a, c])
hp = []
heappush(hp, [0, str(s), s])
fin = [False] * n
while hp:
d, r, u = heappop(hp)
if u == g:
r = list(r)
print(*r)
exit()
if fin[u]: continue
fin[u] = True
for v, c in to[u]:
if fin[v]: continue
heappush(hp, [d + c, r + str(v), v])
main()
mkawa2