#include using namespace std; #define all(v) v.begin(),v.end() using ll = long long; using ull = unsigned long long; using vll=vector; using vvll = vector>; const ll INF=1ll<<60; using vp=vector>; using P = pair; struct unionfind{ ll N; vector par,Rank,Size; unionfind(ll n):N(n){ par=vector(N),Rank=vector(N,1),Size=vector(N,1); for(int i=0;iRank[a]) par[a]=b; else par[b]=a; if(Rank[a]==Rank[b]) Rank[a]++; Size[find(a)]=s; } ll size(ll a){ return Size[find(a)]; } }; int main(){ ll N; cin>>N; unionfind uf(2e5); vll A(2e5); vvll ab(2e5); vp hw(N); vll deg(2e5); for(int i=0;i>hw[i].first>>hw[i].second; hw[i].first--;hw[i].second--; if(hw[i].first!=hw[i].second){ A[hw[i].second]++; deg[hw[i].first]++; deg[hw[i].second]++; } ab[hw[i].first].push_back(hw[i].second); uf.unite(hw[i].first,hw[i].second); } if(uf.size(uf.find(hw[0].first))!=N){ cout<<0< q; for(int i=0;i<2e5;i++){ if(A[i]==0&&ab[i].size())q.push(i); } ll cnt=0; bool a=true; while(!q.empty()){ auto x=q.front();q.pop(); if(q.size()!=0)a=false; cnt++; for(auto to:ab[x]){ A[to]--; if(A[to]==0)q.push(to); } } if(cnt==N){ if(a)cout << 1 << endl; else cout << 0 < st; vll n; ll now=hw[0].first; for(int i=0;i