結果

問題 No.1382 Travel in Mitaru city
ユーザー brthyyjp
提出日時 2021-10-19 01:08:50
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 307 ms / 2,000 ms
コード長 651 bytes
コンパイル時間 141 ms
コンパイル使用メモリ 82,404 KB
実行使用メモリ 100,172 KB
最終ジャッジ日時 2024-09-19 22:02:28
合計ジャッジ時間 14,626 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 68
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

n, m, s, t = map(int, input().split())
s, t = s-1, t-1
P = list(map(int, input().split()))
g = [[] for i in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    g[a].append(b)
    g[b].append(a)
x = P[s]
y = 0
q = []
import heapq
q.append((-P[s], s))
heapq.heapify(q)
visit = [False]*n
visit[s] = True
while q:
    p, v = heapq.heappop(q)
    p *= (-1)
    if x > p:
        y += 1
        x = p
    for u in g[v]:
        if visit[u]:
            continue
        visit[u] = True
        heapq.heappush(q, (-P[u], u))
print(y)
0