結果

問題 No.482 あなたの名は
ユーザー H3PO4
提出日時 2020-08-25 09:59:43
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 1,422 ms / 2,000 ms
コード長 420 bytes
コンパイル時間 85 ms
コンパイル使用メモリ 12,032 KB
実行使用メモリ 79,248 KB
最終ジャッジ日時 2025-01-29 13:20:43
合計ジャッジ時間 45,413 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int1 = lambda x: int(x) - 1

N, K = map(int, input().split())
D = tuple(map(int1, input().split()))

matr = csr_matrix(([1] * N, (D, range(N))), shape=(N, N))
p = connected_components(matr, connection='strong', return_labels=False)
surplus_swap = K - (N - p)
print('YES' if surplus_swap >= 0 and surplus_swap % 2 == 0 else 'NO')
0