結果

問題 No.1382 Travel in Mitaru city
コンテスト
ユーザー Mitarushi
提出日時 2021-02-05 20:37:03
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 293 ms / 2,000 ms
コード長 543 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 385 ms
コンパイル使用メモリ 85,248 KB
実行使用メモリ 103,636 KB
最終ジャッジ日時 2026-03-25 12:11:59
合計ジャッジ時間 13,268 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 68
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import heapq

n, m, s, t = map(int, input().split())
s -= 1
t -= 1
p = [int(i) for i in input().split()]
e = [[] for _ in range(n)]
for _ in range(m):
    a, b = [int(i) - 1 for i in input().split()]
    e[a].append(b)
    e[b].append(a)

used = [False] * n
used[s] = True
q = [(-p[s], s)]
min_p = 10**10
ans = -1
while q:
    i, ind = heapq.heappop(q)
    i *= -1
    if i < min_p:
        min_p = i
        ans += 1
    for j in e[ind]:
        if not used[j]:
            used[j] = True
            heapq.heappush(q, (-p[j], j))
print(ans)
0