#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 7;
int p[N], a[N];
long long dp[N][2];
int n;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d%d", p + i, a + i);
    dp[i][0] = 0;
    dp[i][1] = (long long)-1e15;
  }
  for (int i = n; i > 0; --i) {
    dp[i][1] = max(dp[i][0] + (long long)a[i], dp[i][1]);
    if (p[i] != -1) {
      long long DP0 = max(dp[p[i]][0] + dp[i][0], dp[p[i]][1] + dp[i][1]);
      long long DP1 = max(dp[p[i]][0] + dp[i][1], dp[p[i]][1] + dp[i][0]);
      dp[p[i]][0] = DP0;
      dp[p[i]][1] = DP1;
    }
  }
  cout << dp[1][1] << endl;
}
