#include <bits/stdc++.h>
using namespace std;
multiset<int> lt, rt;
int v[300005], rigth[300005], letf[300005], out = 0, c[300005];
map<int, int> ans, cnt;
map<int, int>::iterator it;
void dfs(int u, int p, int f) {
  if (u == -1) return;
  if (f == 0) lt.insert(v[p]);
  if (f == 1) rt.insert(v[p]);
  int x = *(lt.begin()), fl = 0;
  if (v[u] > x) fl = 1;
  x = *(rt.rbegin());
  if (v[u] < x) fl = 1;
  ans[v[u]] &= fl;
  dfs(letf[u], u, 0);
  dfs(rigth[u], u, 1);
  if (f == 0) lt.erase(lt.find(v[p]));
  if (f == 1) rt.erase(rt.find(v[p]));
}
int main() {
  int n, i, root;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> v[i] >> letf[i] >> rigth[i];
    if (letf[i] != -1) c[letf[i]]++;
    if (rigth[i] != -1) c[rigth[i]]++;
    ans[v[i]] = 1;
    cnt[v[i]]++;
  }
  for (i = 1; i <= n; i++) {
    if (!c[i]) {
      root = i;
      break;
    }
  }
  lt.insert((int)1e9 + 7);
  rt.insert(-(int)1e9 + 7);
  dfs(root, -1, -1);
  for (it = ans.begin(); it != ans.end(); it++)
    out += ((it->second) == 1) * cnt[it->first];
  cout << out;
  return 0;
}
