結果

問題 No.482 あなたの名は
ユーザー siman
提出日時 2020-11-16 02:53:59
言語 Ruby
(3.4.1)
結果
WA  
実行時間 -
コード長 415 bytes
コンパイル時間 305 ms
コンパイル使用メモリ 7,680 KB
実行使用メモリ 44,068 KB
最終ジャッジ日時 2024-07-23 01:25:14
合計ジャッジ時間 9,786 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26 WA * 2
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N, K = gets.split.map(&:to_i)
D = gets.split.map(&:to_i)
E = Hash.new

D.each.with_index(1) do |d, idx|
  E[idx] = d
end

visited = Hash.new(false)
cnt = 0

(1..N).each do |n|
  next if visited[n]

  cnt += 1
  queue = []
  queue << n

  until queue.empty?
    v = queue.shift

    next if visited[v]
    visited[v] = true

    queue << E[v]
  end
end

if (K - (N - cnt)) % 2 == 0
  puts 'YES'
else
  puts 'NO'
end
0