結果

問題 No.482 あなたの名は
ユーザー simansiman
提出日時 2020-11-16 02:53:59
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 415 bytes
コンパイル時間 41 ms
コンパイル使用メモリ 11,256 KB
実行使用メモリ 46,160 KB
最終ジャッジ日時 2023-09-30 07:10:11
合計ジャッジ時間 9,788 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
15,128 KB
testcase_01 AC 81 ms
15,128 KB
testcase_02 AC 85 ms
15,064 KB
testcase_03 AC 82 ms
15,256 KB
testcase_04 AC 80 ms
15,116 KB
testcase_05 AC 81 ms
15,060 KB
testcase_06 AC 82 ms
15,120 KB
testcase_07 AC 84 ms
15,136 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 84 ms
15,012 KB
testcase_11 AC 84 ms
15,008 KB
testcase_12 AC 84 ms
15,032 KB
testcase_13 AC 84 ms
15,116 KB
testcase_14 AC 81 ms
15,292 KB
testcase_15 AC 385 ms
45,480 KB
testcase_16 AC 386 ms
45,924 KB
testcase_17 AC 389 ms
45,696 KB
testcase_18 AC 393 ms
45,536 KB
testcase_19 AC 379 ms
45,700 KB
testcase_20 AC 386 ms
46,160 KB
testcase_21 AC 395 ms
46,072 KB
testcase_22 AC 389 ms
45,652 KB
testcase_23 AC 383 ms
45,468 KB
testcase_24 AC 389 ms
45,568 KB
testcase_25 AC 386 ms
45,924 KB
testcase_26 AC 385 ms
45,632 KB
testcase_27 AC 392 ms
45,536 KB
testcase_28 AC 386 ms
45,464 KB
testcase_29 AC 368 ms
45,812 KB
testcase_30 AC 82 ms
15,300 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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