#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int fa[N], a[N];
long long dp[N][2];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &fa[i], &a[i]);
    dp[i][0] = 0;
    dp[i][1] = -(long long)1000000;
  }
  for (int i = n; i > 0; i--) {
    dp[i][1] = max(dp[i][1], dp[i][0] + a[i]);
    if (i == 1) break;
    long long n0, n1;
    n0 = max(dp[fa[i]][0] + dp[i][0], dp[fa[i]][1] + dp[i][1]);
    n1 = max(dp[fa[i]][1] + dp[i][0], dp[fa[i]][0] + dp[i][1]);
    dp[fa[i]][0] = n0;
    dp[fa[i]][1] = n1;
  }
  printf("%I64d\n", dp[1][1]);
}
