結果

問題 No.1382 Travel in Mitaru city
ユーザー rlangevin
提出日時 2023-04-13 12:47:28
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 447 ms / 2,000 ms
コード長 622 bytes
コンパイル時間 193 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 96,104 KB
最終ジャッジ日時 2024-10-09 11:02:14
合計ジャッジ時間 18,461 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 68
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline = sys.stdin.readline
from heapq import *

N, M, S, T = map(int, readline().split())
S, T = S - 1, T - 1
P = list(map(int, readline().split()))
G = [[] for i in range(N)]
for i in range(M):
    A, B = map(int, readline().split())
    A, B = A - 1, B - 1
    G[A].append(B)
    G[B].append(A)

Q = []
Q.append((-P[S], S))
ans = -1
now = 10 ** 18
seen = [0] * N
while Q:
    c, u = heappop(Q)
    c = -c
    if seen[u]:
        continue
    seen[u] = 1
    if c < now:
        ans += 1
        now = c
    for v in G[u]:
        if seen[v]:
            continue
        heappush(Q, (-P[v], v))

print(ans)
0