#include <bits/stdc++.h>
using namespace std;
inline long long qr() {
  long long x = 0, f = 1;
  char ch;
  while (!isdigit(ch = getchar()))
    if (ch == '-') f = -1;
  for (; isdigit(ch); x = x * 10 + ch - 48, ch = getchar())
    ;
  return x * f;
}
long long f[200010][2];
int a[200010];
vector<int> g[200010];
void dfs(int u) {
  f[u][1] = -0x3f3f3f3f;
  long long t1, t2;
  for (int i = 0; i < g[u].size(); ++i) {
    int v = g[u][i];
    dfs(v);
    t1 = f[u][1];
    t2 = f[u][0];
    f[u][1] = max(t2 + f[v][1], t1 + f[v][0]);
    f[u][0] = max(t2 + f[v][0], t1 + f[v][1]);
  }
  f[u][1] = max(f[u][1], f[u][0] + a[u]);
}
int main() {
  int n = qr();
  for (int i = 1; i <= n; ++i) {
    int x = qr(), y = qr();
    if (~x) g[x].push_back(i);
    a[i] = y;
  }
  dfs(1);
  printf("%lld\n", max(f[1][0], f[1][1]));
  return 0;
}
