#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int sum = 0;
  char c = getchar();
  bool f = 0;
  while (c < '0' || c > '9') {
    if (c == '-') f = 1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    sum = sum * 10 + c - '0';
    c = getchar();
  }
  if (f) return -sum;
  return sum;
}
const int N = 100005;
int n, v[N], ls[N], rs[N], ID[N];
map<int, int> H;
set<int> S[N];
set<int>::iterator it, ed;
inline void dfs(int k) {
  int x = 0, y = 0;
  if (ls[k] != -1) {
    dfs(ls[k]);
    x = ID[ls[k]];
    while (!S[x].empty()) {
      it = S[x].end();
      it--;
      if (*it >= v[k])
        S[x].erase(it);
      else
        break;
    }
  }
  if (rs[k] != -1) {
    dfs(rs[k]);
    y = ID[rs[k]];
    while (!S[y].empty()) {
      it = S[y].begin();
      if (*it <= v[k])
        S[y].erase(it);
      else
        break;
    }
  }
  if (!x && !y) {
    S[k].insert(v[k]);
    return;
  }
  if (!x) {
    ID[k] = y;
    S[y].insert(v[k]);
    return;
  }
  if (!y) {
    ID[k] = x;
    S[x].insert(v[k]);
    return;
  }
  if (S[x].size() < S[y].size()) swap(x, y);
  ID[k] = x;
  for (it = S[y].begin(), ed = S[y].end(); it != ed; it++) S[x].insert(*it);
  S[x].insert(v[k]);
}
bool hav[N];
int rt;
int main() {
  int i, j;
  n = read();
  for (i = 1; i <= n; i++) {
    v[i] = read(), ls[i] = read(), rs[i] = read();
    H[v[i]]++;
    ID[i] = i;
    if (ls[i] != -1) hav[ls[i]] = 1;
    if (rs[i] != -1) hav[rs[i]] = 1;
  }
  for (i = 1; i <= n; i++)
    if (!hav[i]) {
      rt = i;
      break;
    }
  dfs(rt);
  for (it = S[ID[rt]].begin(), ed = S[ID[rt]].end(); it != ed; it++)
    n -= H[*it];
  printf("%d", n);
  return 0;
}
