void muri(){ wt(0); exit(0); } char vis[2d5+1]; int ioc[2d5+1]; { unionFind u; u.walloc(2d5+1,1); ll@n; ll x=0,y=0,z=0; rep(n){ ll@h,@w; vis[h]=1; vis[w]=1; ioc[h]+=1; ioc[w]-=1; u(h,w); x=h; } x=u(x); rep(i,1,2d5+1){ if(vis[i]){ if(u(i)!=x||ioc[i]<-1||ioc[i]>1){ muri(); } if(ioc[i]==-1){ if(y&1){ muri(); } y|=1; } if(ioc[i]==1){ if(y&2){ muri(); } y|=2; } z+=1; } } wt(y?1:z); }