read n m read -aa while read u v do 'r|=d&&x[u=u*2|d<0]&&x[u]-d,x[u]|=d' $[d=a[--u]-a[--v],_,u=v,d=-d,_] done NO echo ${_[r]-YES}