結果

問題 No.482 あなたの名は
ユーザー Daisuke MiyakawaDaisuke Miyakawa
提出日時 2022-03-22 21:25:38
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 318 ms / 2,000 ms
コード長 505 bytes
コンパイル時間 429 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 45,940 KB
最終ジャッジ日時 2024-10-10 15:44:13
合計ジャッジ時間 6,982 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

from typing import List

N, K = [int(e) for e in input().split()]
D: List[int] = []

remaining = set()
for i, e in enumerate(input().split()):
    remaining.add(i)
    D.append(int(e) - 1)

count = 0
while remaining:
    node_i = remaining.pop()
    linked = set()
    while True:
        linked.add(node_i)
        node_i = D[node_i]
        if node_i in linked:
            break
        remaining.remove(node_i)
        count += 1

k = K - count
print("YES" if k >= 0 and k % 2 == 0 else "NO", end="")
0