line = gets.chomp! abort "line 1 format error" unless line=~/^\d+ \d+$/ n,m = line.split.map &:to_i line = gets.chomp! abort "line 2 format error" unless line=~/^\d+(?: \d+)*$/ aa = line.split.map &:to_i abort "line 2 vector_size error" unless aa.size == n edges = [] m.times{|i| line = gets.chomp! abort "line #{i+3} format error" unless line=~/^\d+ \d+$/ edges << line.split.map(&:to_i) } abort "too many lines" unless !gets def yes;puts "YES";exit(0);end def no ;puts "NO"; exit(0);end def kadomatu?(a,b,c) a!=b&&b!=c&&c!=a&&((ac)||(a>b&&b (pair[0][0] == pair[1][0]) -> pair[1][1] となっているケース yes if kadomatu?(pair[0][1], pair[0][0], pair[1][1]) elsif pair[0][0] == pair[1][1] # pair[0][1] -> (pair[0][0] == pair[1][1]) -> pair[1][0] となっているケース yes if kadomatu?(pair[0][1], pair[1][1], pair[1][0]) end } no