#include <bits/stdc++.h>
using namespace std;
int n, mn[100000], mx[100000], vis[100000];
pair<int, pair<int, int>> a[100000];
set<int> s;
map<int, int> mp;
void dfs(int u) {
  if (a[u].second.first != -1) {
    mn[a[u].second.first] = mn[u];
    mx[a[u].second.first] = min(a[u].first, mx[u]);
    dfs(a[u].second.first);
  }
  if (a[u].second.second != -1) {
    mn[a[u].second.second] = max(a[u].first, mn[u]);
    mx[a[u].second.second] = mx[u];
    dfs(a[u].second.second);
  }
}
int main() {
  cin >> n;
  for (int i = 0, x, y, node; i < n; ++i) {
    scanf("%d%d%d", &a[i].first, &a[i].second.first, &a[i].second.second);
    if (a[i].second.first != -1) {
      --a[i].second.first;
    }
    if (a[i].second.second != -1) {
      --a[i].second.second;
    }
    s.insert(a[i].second.first);
    s.insert(a[i].second.second);
  }
  int root = 0;
  for (int i = 0; i < n; ++i) {
    if (s.find(i) == s.end()) {
      root = i;
    }
  }
  mn[root] = -2e9;
  mx[root] = 2e9;
  int ans = 0;
  dfs(root);
  for (int i = 0; i < n; ++i) {
    if (mp.find(a[i].first) == mp.end()) {
      mp[a[i].first] = 1;
    }
    mp[a[i].first] =
        mp[a[i].first] && (mn[i] > a[i].first || mx[i] < a[i].first);
  }
  for (int i = 0; i < n; ++i) {
    ans += mp[a[i].first];
  }
  cout << ans;
  return 0;
}
