結果

問題 No.482 あなたの名は
コンテスト
ユーザー H3PO4
提出日時 2020-08-25 09:59:43
言語 Python3
(3.14.3 + numpy 2.4.4 + scipy 1.17.1)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 1,694 ms / 2,000 ms
+ 330µs
コード長 420 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 517 ms
コンパイル使用メモリ 21,540 KB
実行使用メモリ 84,388 KB
最終ジャッジ日時 2026-07-20 09:38:45
合計ジャッジ時間 58,335 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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