int main(void){
 
  int i,node,c,l,r;

  scanf("%d",&n);
 
  T = malloc(n * sizeof(Tree));
 
  for(i=0;i<n;i++){
    T[i].id = T[i].p = T[i].s = T[i].l = T[i].r = -1;
    T[i].c = 0;
  }
 
  for(i=0;i<n;i++){
    c = 0;
    scanf("%d",&node);
    scanf("%d %d",&T[node].l,&T[node].r);
    T[node].id = node;

    if(T[node].l != -1 && T[node].r != -1){
    T[T[node].l].p = T[T[node].r].p = node;
    T[T[node].l].s = T[node].r;
    T[T[node].r].s = T[node].l;
    }



    if(T[node].l == -1) c++;
    if(T[node].r == -1) c++;

    if(c == 0) T[node].c = 2;
    else if(c == 1) T[node].c = 1;
    else T[node].c = 0;

  }
  print();
  free(T);
  return 0;
}