結果

問題 No.482 あなたの名は
ユーザー maspy
提出日時 2020-01-27 21:00:42
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 227 ms / 2,000 ms
コード長 459 bytes
コンパイル時間 121 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 29,536 KB
最終ジャッジ日時 2024-09-14 14:15:00
合計ジャッジ時間 5,141 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# あ、隣接じゃない

N,K,*D = map(int,read().split())

visited = [0] * (N+1)

cycle = 0
for n in range(1,N+1):
    if not visited[n]:
        cycle += 1
    while True:
        n = D[n-1]
        if visited[n]:
            break
        visited[n] = 1

x = N - cycle

answer = 'YES' if (K>=x) and ((K-x)%2 == 0) else 'NO'
print(answer)
0