#include <bits/stdc++.h>
using namespace std;
bool rt[100005];
int v[100005], l[100005], r[100005];
int main() {
  int n;
  scanf("%d", &n);
  memset(rt, true, sizeof(rt));
  for (int i = 0; i < n; i++) {
    scanf("%d%d%d", &v[i], &l[i], &r[i]);
    if (l[i] >= 0) rt[--l[i]] = false;
    if (r[i] >= 0) rt[--r[i]] = false;
  }
  int root = 0;
  for (int i = 0; i < n; i++)
    if (rt[i]) root = i;
  queue<pair<int, pair<int, int> > > q;
  map<int, int> fails;
  fails[v[root]] = -1;
  int cnt = 0;
  q.push(make_pair(root, make_pair(-1234567890, 1234567890)));
  while (!q.empty()) {
    int cur = q.front().first;
    pair<int, int> range = q.front().second;
    q.pop();
    if ((v[cur] <= range.first || range.second <= v[cur]) &&
        fails[v[cur]] != -1) {
      cnt++;
      fails[v[cur]]++;
    }
    if (v[cur] > range.first && v[cur] < range.second) {
      if (fails[v[cur]] > 0) cnt -= fails[v[cur]];
      fails[v[cur]] = -1;
    }
    if (l[cur] >= 0)
      q.push(make_pair(l[cur],
                       make_pair(range.first, min<int>(range.second, v[cur]))));
    if (r[cur] >= 0)
      q.push(make_pair(r[cur],
                       make_pair(max<int>(range.first, v[cur]), range.second)));
  }
  cout << cnt << endl;
  return 0;
}
