#include <bits/stdc++.h>
using namespace std;
bool debug = 1;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
long long ln, lk, lm;
int p[200105], a[200105];
long long dp[200105][2];
int main() {
  scanf("%d", &n);
  for (int(i) = 1; (i) <= (int)(n); (i)++) scanf("%d%d", p + i, a + i);
  for (int i = n; i; i--) {
    dp[i][1] = max(dp[i][0] + a[i], dp[i][1]);
    if (p[i] != -1) {
      int f = p[i];
      long long tp = dp[f][0], tp1 = dp[f][1];
      dp[f][0] = dp[f][0] + dp[i][0];
      if (dp[f][1] && dp[i][1]) dp[f][0] = max(dp[f][0], dp[f][1] + dp[i][1]);
      if (tp1 != 0) dp[f][1] = max(tp1, tp1 + dp[i][0]);
      if (dp[i][1] != 0) dp[f][1] = max(dp[f][1], tp + dp[i][1]);
    }
  }
  printf("%lld\n", max(dp[1][0], dp[1][1]));
  return 0;
}
