#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5;
int efficiency[MAXN + 1];
vector<int> G[MAXN + 1];
long long dp[MAXN + 1][2], tmp[2];
void init() {
  memset(dp, 0, sizeof(dp));
  for (int i = 0; i < MAXN + 1; i++) {
    G[i].clear();
  }
}
void solve(int u) {
  dp[u][0] = 0;
  dp[u][1] = -(1LL << 40);
  for (int v : G[u]) {
    solve(v);
    for (int j = 0; j < 2; j++) {
      tmp[j] = dp[u][j];
    }
    tmp[0] = max(dp[u][0] + dp[v][0], dp[u][1] + dp[v][1]);
    tmp[1] = max(dp[u][0] + dp[v][1], dp[u][1] + dp[v][0]);
    for (int j = 0; j < 2; j++) {
      dp[u][j] = tmp[j];
    }
  }
  dp[u][1] = max(dp[u][1], dp[u][0] + efficiency[u]);
}
int main() {
  int n;
  while (~scanf("%d", &n)) {
    init();
    for (int i = 0; i < n; i++) {
      int superior;
      scanf("%d%d", &superior, efficiency + i + 1);
      if (~superior) {
        G[superior].push_back(i + 1);
      }
    }
    solve(1);
    printf("%I64d\n", dp[1][1]);
  }
  return 0;
}
