#include <bits/stdc++.h>
using namespace std;
int v[100005], ls[100005], rs[100005];
int t[100005], ans;
bool isroot[100005];
void solve(int rt, int L, int R) {
  if (rt == -1 || L > R) return;
  if (t[L] <= v[rt] && t[R] >= v[rt]) {
    int l, r, tl, tr;
    tl = L, tr = R;
    while (tl < tr) {
      int tm = (tl + tr) >> 1;
      if (t[tm] < v[rt])
        tl = tm + 1;
      else
        tr = tm;
    }
    l = tl;
    tl = L, tr = R;
    while (tl < tr) {
      int tm = (tl + tr + 1) >> 1;
      if (t[tm] > v[rt])
        tr = tm - 1;
      else
        tl = tm;
    }
    r = tl;
    for (int i = l; i <= r; ++i)
      if (t[i] == v[rt]) ++ans;
  }
  int l, r;
  l = L, r = L - 1;
  if (t[L] >= v[rt])
    r = L - 1;
  else {
    int tl = L, tr = R;
    while (tl < tr) {
      int tm = (tl + tr + 1) >> 1;
      if (t[tm] >= v[rt])
        tr = tm - 1;
      else
        tl = tm;
    }
    r = tl;
  }
  solve(ls[rt], l, r);
  r = R;
  if (t[R] <= v[rt])
    l = R + 1;
  else {
    int tl = L, tr = R;
    while (tl < tr) {
      int tm = (tl + tr) >> 1;
      if (t[tm] <= v[rt])
        tl = tm + 1;
      else
        tr = tm;
    }
    l = tl;
  }
  solve(rs[rt], l, r);
}
int main() {
  int n;
  scanf("%d", &n);
  memset(isroot, true, sizeof isroot);
  for (int i = 1; i <= n; ++i) {
    scanf("%d%d%d", v + i, ls + i, rs + i);
    t[i] = v[i];
    if (ls[i] != -1) isroot[ls[i]] = false;
    if (rs[i] != -1) isroot[rs[i]] = false;
  }
  int root;
  for (int i = 1; i <= n; ++i)
    if (isroot[i]) {
      root = i;
      break;
    }
  sort(t + 1, t + 1 + n);
  ans = 0, solve(root, 1, n);
  printf("%d\n", n - ans);
  return 0;
}
