#define rep(i,n) for(int i=0;i<(int)(n);i++) #define ALL(v) v.begin(),v.end() typedef long long ll; #include #include using namespace std; using namespace atcoder; int indeg[200200],rdeg[200200]; vector G[200200]; int seen[200200]; template vector compress(vector &X){ vector vals=X; sort(vals.begin(),vals.end()); vals.erase(unique(vals.begin(), vals.end()),vals.end()); for(int i=0;i<(int)X.size(); i++){ X[i]=lower_bound(vals.begin(),vals.end(),X[i])-vals.begin(); } return vals; } void dfs(int v){ seen[v]=1; for(auto nv:G[v]){ if(seen[nv]) continue; dfs(nv); } } int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); int n; cin>>n; vector A(2*n); rep(i,2*n) cin>>A[i]; compress(A); vector H(n),W(n); int manum=0; rep(i,n){ H[i]=A[2*i],W[i]=A[2*i+1]; manum=max({manum,H[i],W[i]}); } scc_graph g(manum+1); rep(i,n){ g.add_edge(H[i],W[i]); rdeg[H[i]]++; indeg[W[i]]++; G[H[i]].push_back(W[i]); } auto scc=g.scc(); int cnt=0; rep(i,n){ if((rdeg[i]+indeg[i])%2==1) cnt++; } if(scc.size()==1){ if(cnt==0) cout<1) b=false; } if(b) cout<<1<