#include <bits/stdc++.h>
using namespace std;
template <typename T>
void r1(T &x) {
  x = 0;
  char c(getchar());
  int f(1);
  for (; c < '0' || c > '9'; c = getchar())
    if (c == '-') f = -1;
  for (; '0' <= c && c <= '9'; c = getchar()) x = (x * 10) + (c ^ 48);
  x *= f;
}
const int maxn = 2e5 + 5;
const int maxm = maxn << 1;
long long n, m;
vector<long long> vc[maxn];
long long v[maxn], rt;
long long f[maxn][2];
void dfs(long long p) {
  f[p][1] = -1e15;
  for (vector<long long>::iterator it = vc[p].begin(); it != vc[p].end();
       ++it) {
    dfs(*it);
    long long f0 = f[p][0], f1 = f[p][1];
    f[p][0] = max(f0 + f[*it][0], f1 + f[*it][1]);
    f[p][1] = max(f1 + f[*it][0], f0 + f[*it][1]);
  }
  long long f0 = f[p][0], f1 = f[p][1];
  f[p][1] = max(f1, f0 + v[p]);
}
signed main() {
  long long i, j;
  r1(n);
  for (i = 1; i <= n; ++i) {
    long long u;
    r1(u), r1(v[i]);
    if (u == -1)
      rt = i;
    else
      vc[u].push_back(i);
  }
  dfs(rt);
  printf("%lld\n", max(f[rt][0], f[rt][1]));
  return 0;
}
