#include <bits/stdc++.h>
using namespace std;
const int MXN = 1e5 + 5;
int n, child[MXN], val[MXN], black[MXN];
pair<int, int> desc[MXN];
void dfs(int u, map<int, int>& lm, map<int, int>& rm) {
  if (!lm.empty() && val[u] > lm.begin()->first) black[u] = 1;
  if (!rm.empty() && val[u] < rm.rbegin()->first) black[u] = 1;
  if (desc[u].first != -1) {
    lm[val[u]]++;
    dfs(desc[u].first, lm, rm);
    lm[val[u]]--;
    if (lm[val[u]] == 0) lm.erase(val[u]);
  }
  if (desc[u].second != -1) {
    rm[val[u]]++;
    dfs(desc[u].second, lm, rm);
    rm[val[u]]--;
    if (rm[val[u]] == 0 != -1) rm.erase(val[u]);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  map<int, int> cnts, cnts_black;
  for (int i = 1; i <= n; i++) {
    int v, l, r;
    cin >> v >> l >> r;
    child[l] = child[r] = 1;
    val[i] = v;
    desc[i] = make_pair(l, r);
    cnts[val[i]]++;
  }
  int root = -1;
  for (int i = 1; i <= n; i++) {
    if (!child[i]) {
      root = i;
      break;
    }
  }
  map<int, int> lm, rm;
  dfs(root, lm, rm);
  for (int i = 1; i <= n; i++) {
    if (black[i]) cnts_black[val[i]]++;
  }
  int res = 0;
  for (int i = 1; i <= n; i++) {
    if (cnts[val[i]] == cnts_black[val[i]]) res++;
  }
  cout << res << endl;
  return 0;
}
