#include <bits/stdc++.h>
using namespace std;
int n;
int a[200007];
long long dp[200007][2];
vector<int> e[200007];
void add(int u, int v) { e[u].push_back(v); }
void dfs(int u) {
  if (!e[u].size()) {
    dp[u][1] = a[u];
    dp[u][0] = 0;
    return;
  }
  dp[u][1] = -(1 << 29);
  dp[u][0] = 0;
  long long t1, t0;
  for (int i = 0; i < e[u].size(); i++) {
    int v = e[u][i];
    dfs(v);
    t1 = dp[u][1];
    t0 = dp[u][0];
    dp[u][1] = max(t0 + dp[v][1], t1 + dp[v][0]);
    dp[u][0] = max(t0 + dp[v][0], t1 + dp[v][1]);
  }
  dp[u][1] = max(dp[u][1], dp[u][0] + a[u]);
}
int main() {
  int x, y;
  while (~scanf("%d", &n)) {
    for (int i = 0; i < 200007; i++) e[i].clear();
    for (int i = 1; i <= n; i++) {
      scanf("%d%d", &x, &y);
      if (x != -1) add(x, i);
      a[i] = y;
    }
    dfs(1);
    printf("%I64d\n", dp[1][1]);
  }
}
