#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 7;
const long long inf = 0x3f3f3f3f3f3f3f3f;
vector<int> son[maxn];
long long a[maxn];
long long dp[maxn][2], ans;
void init(int n) {
  ans = 0;
  for (int i = 0; i < maxn; ++i) son[i].clear();
  for (int i = 1; i <= n; ++i) {
    long long p;
    cin >> p >> a[i];
    if (p != -1) son[p].push_back(i);
    ans = max(ans, a[i]);
  }
}
void dfs(int t) {
  if (son[t].size() == 0) {
    dp[t][1] = a[t];
    dp[t][0] = 0;
    return;
  }
  dp[t][0] = 0;
  dp[t][1] = -inf;
  for (int i = 0; i < son[t].size(); ++i) {
    long long t1 = dp[t][1];
    long long t0 = dp[t][0];
    int v = son[t][i];
    dfs(v);
    dp[t][0] = max(t0 + dp[v][0], t1 + dp[v][1]);
    dp[t][1] = max(t0 + dp[v][1], t1 + dp[v][0]);
  }
  dp[t][1] = max(dp[t][1], dp[t][0] + a[t]);
}
void solve(int n) {
  memset(dp, 0, sizeof(dp));
  dfs(1);
  ans = max(dp[1][0], dp[1][1]);
  printf("%I64d\n", ans);
}
int main() {
  int n;
  while (scanf("%d", &n) != EOF) {
    init(n);
    solve(n);
  }
  return 0;
}
