結果

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

ソースコード

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 or k % 2 == 0 else "NO", end="")
0