#include <bits/stdc++.h>
using namespace std;
const int mxn = 2e5 + 5;
vector<int> g[mxn];
int n, m;
int a[mxn], deg[mxn];
int l[mxn], r[mxn], root;
int ans;
map<int, int> tag, ccc;
inline void dfs(int x, int mn, int mx) {
  if (a[x] > mx or a[x] < mn) {
    if (tag[a[x]] == 1)
      ;
    else
      tag[a[x]] = -1;
  } else
    tag[a[x]] = 1;
  if (~l[x]) dfs(l[x], mn, min(mx, a[x]));
  if (~r[x]) dfs(r[x], max(mn, a[x]), mx);
}
inline void solve() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i] >> l[i] >> r[i];
    ++ccc[a[i]];
    if (~l[i]) ++deg[l[i]];
    if (~r[i]) ++deg[r[i]];
  }
  for (int i = 1; i <= n; ++i)
    if (!deg[i]) {
      root = i;
      break;
    }
  dfs(root, -1, 1000000001);
  int cnt = 0;
  for (map<int, int>::iterator it = tag.begin(); it != tag.end(); it++)
    if ((it->second) == -1) cnt += ccc[it->first];
  cout << cnt << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int T = 1;
  for (; T--;) solve();
}
