#include <bits/stdc++.h>
using namespace std;
long long read() {
  int a = 0, b = getchar();
  while (!isdigit(b)) b = getchar();
  while (isdigit(b)) a = a * 10 + b - '0', b = getchar();
  return a;
}
int n, c[100005], l[100005], r[100005], b[100005], a[100005];
int gg(int ab, int l1, int r1) {
  if (!~ab) return r1 - l1 + 1;
  int x = lower_bound(a + l1, a + r1 + 1, c[ab]) - a, y = x - 1;
  while (y < r1 and a[y + 1] == c[ab]) y++;
  return gg(l[ab], l1, x - 1) + gg(r[ab], y + 1, r1);
}
int gao(int ab) {
  int x = 0, y = upper_bound(a, a + n, c[ab]) - a;
  int res = 0;
  while (x < y) x += x & -x, res++;
  while (x == y) res--;
  if (x == n) res--;
  return res;
}
int main() {
  n = read();
  for (int i = 1; i <= n; i++) {
    scanf("%d%d%d", c + i, l + i, r + i);
    b[l[i]] = b[r[i]] = 1;
    a[++a[0]] = c[i];
  }
  int ab, ac = 1e9;
  for (int i = 1; i <= n; i++)
    if (!b[i]) ab = i;
  sort(a + 1, a + n + 1);
  ab += n / ac;
  printf("%d", gg(ab, 1, n));
  return 0;
}
