結果

問題 No.1382 Travel in Mitaru city
ユーザー Mitarushi
提出日時 2021-02-05 20:37:03
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 384 ms / 2,000 ms
コード長 543 bytes
コンパイル時間 223 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 98,576 KB
最終ジャッジ日時 2024-07-04 03:38:20
合計ジャッジ時間 16,808 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 68
権限があれば一括ダウンロードができます

ソースコード

diff #

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