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