結果
| 問題 | No.1370 置換門松列 | 
| コンテスト | |
| ユーザー |  siman | 
| 提出日時 | 2022-05-13 15:06:29 | 
| 言語 | Ruby (3.4.1) | 
| 結果 | 
                                RE
                                 
                             | 
| 実行時間 | - | 
| コード長 | 674 bytes | 
| コンパイル時間 | 477 ms | 
| コンパイル使用メモリ | 7,552 KB | 
| 実行使用メモリ | 35,160 KB | 
| 最終ジャッジ日時 | 2024-11-08 04:21:13 | 
| 合計ジャッジ時間 | 8,063 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 5 | 
| other | AC * 24 RE * 1 | 
コンパイルメッセージ
Main.rb:48: warning: assigned but unused variable - e Syntax OK
ソースコード
require 'tsort'
class Hash
  include TSort
  alias tsort_each_node each_key
  def tsort_each_child(node, &block)
    fetch(node).each(&block)
  end
end
N, M = gets.split.map(&:to_i)
A = gets.split.map(&:to_i)
E = Hash.new { |h, k| h[k] = [] }
A.each_cons(3) do |a, _, c|
  if a == c
    puts "No"
    exit
  end
end
A.each_cons(2).with_index do |(u, v), i|
  if u == v
    puts "No"
    exit
  end
  if i.even?
    E[u] << v
  else
    E[v] << u
  end
end
1.upto(M) do |i|
  E[i] = E[i].uniq
end
ans = Array.new(M, -1)
begin
  E.tsort.each.with_index(1) do |u, a|
    ans[u - 1] = a
  end
  puts "Yes"
  puts ans.join(" ")
rescue TSort::Cyclic => e
  puts "No"
end
            
            
            
        