#include <bits/stdc++.h>
using namespace std;
long long a[200010];
vector<int> e[200010];
long long f[200010][2];
void work(int u) {
  if (e[u].empty()) {
    f[u][0] = 0;
    f[u][1] = a[u];
  } else {
    f[u][0] = 0;
    f[u][1] = -10000000000000;
    for (int i = 0; i < e[u].size(); i++) {
      int v = e[u][i];
      work(v);
      long long t0 = f[u][0], t1 = f[u][1];
      f[u][0] = max(t0 + f[v][0], t1 + f[v][1]);
      f[u][1] = max(t0 + f[v][1], t1 + f[v][0]);
    }
    f[u][1] = max(f[u][0] + a[u], f[u][1]);
  }
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int x;
    long long y;
    scanf("%d%lld", &x, &y);
    if (i != 1) {
      e[x].push_back(i);
    }
    a[i] = y;
  }
  work(1);
  printf("%lld\n", max(f[1][1], f[1][0]));
  return 0;
}
