#include#include #include #include using namespace std;const int N=110;int pre[N],nex[N];int z[N],y[N];int wan[N];int fa[N];int findx(int x){ return fa[x]=(x==fa[x]?x:findx(fa[x]));}int main(){ int n; scanf("%d",&n); int tot1=0,tot2=0,tot3=0; for(int i=0; i<=n; ++i) fa[i]=i; for(int i=1; i<=n; ++i) { scanf("%d%d",&pre[i],&nex[i]); int x1=findx(i),x2=findx(pre[i]),x3=findx(nex[i]); if(x1!=x2&&x2!=0) fa[x2]=x1; if(x1!=x3&&x3!=0) fa[x3]=x1; if(pre[i]==0&&nex[i]==0) { wan[tot2++]=i; continue; } if(pre[i]==0) z[tot1++]=i; if(nex[i]==0) y[tot3++]=i; } bool used[120]; memset(used,0,sizeof(used)); for(int i=0; i