結果

問題 No.1382 Travel in Mitaru city
コンテスト
ユーザー flippergo
提出日時 2026-11-08 10:14:21
言語 PyPy3
(8.0.1 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
MLE  
実行時間 -
コード長 891 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 84 ms
コンパイル使用メモリ 64,640 KB
実行使用メモリ 673,808 KB
最終ジャッジ日時 2026-11-08 10:14:37
合計ジャッジ時間 10,773 ms
ジャッジサーバーID
(参考情報)
judge7_0 / judge4_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 3 MLE * 1 -- * 64
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import heapq
import sys
sys.setrecursionlimit(10**6)
N,M,s,t = map(int,input().split())
P = [0]+list(map(int,input().split()))
G = {i:[] for i in range(1,N+1)}
for _ in range(M):
    a,b = map(int,input().split())
    G[a].append(b)
    G[b].append(a)
T = [[i,0] for i in range(N+1)]
def tfind(x):
    if T[x][0]!=x:
        T[x][0] = tfind(T[x][0])
    return T[x][0]
def tunion(x,y):
    rx = tfind(x)
    ry = tfind(y)
    if rx==ry:
        return
    if T[rx][1]>T[ry][1]:
        T[ry][0] = rx
    elif T[rx][1]<T[ry][1]:
        T[rx][0] = ry
    else:
        T[ry][0] = rx
        T[rx][1] += 1
que = []
X = P[s]
Y = 0
for x in G[s]:
    heapq.heappush(que,(-P[x],x))
while que:
    p,x = heapq.heappop(que)
    p = -p
    if p<X:
        Y += 1
        X = p
    tunion(s,x)
    for y in G[x]:
        if tfind(y)!=tfind(s):
            heapq.heappush(que,(-P[y],y))
print(Y)      
0