c=*0..gets.to_i r=->u{u==c[u]?u:c[u]=r[c[u]]} h={} $<.map{|s|h[a=s[/\d+/].to_i]^=1;h[b=$'.to_i]^=c[r[a]]=r[b]} puts h.values.count(!p)>2||(h.keys.map(&r)|[])[1]?:NO: :YES