結果

問題 No.1382 Travel in Mitaru city
ユーザー H3PO4
提出日時 2021-02-07 20:46:51
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 524 bytes
コンパイル時間 269 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 110,208 KB
最終ジャッジ日時 2024-07-04 13:52:46
合計ジャッジ時間 89,335 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30 WA * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

from scipy.sparse.csgraph import connected_components
from scipy.sparse import csr_matrix

N, M, S, T = map(int, input().split())
S -= 1
T -= 1
P = tuple(map(int, input().split()))
frm, to = [0] * M, [0] * M
for i in range(M):
    a, b = (int(x) - 1 for x in input().split())
    frm[i] = a
    to[i] = b

matr = csr_matrix(([1] * M, (frm, to)), shape=(N, N))
p, labels = connected_components(matr)

ls, ps = labels[S], P[S]
st = set()
for x, p in zip(labels, P):
    if x == ls and p < ps:
        st.add(p)
print(len(st))
0