結果

問題 No.482 あなたの名は
ユーザー Daisuke Miyakawa
提出日時 2022-03-22 21:16:10
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 503 bytes
コンパイル時間 456 ms
コンパイル使用メモリ 82,028 KB
実行使用メモリ 140,352 KB
最終ジャッジ日時 2024-10-10 15:33:38
合計ジャッジ時間 5,728 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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