#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
long long dp[MAXN][3];
vector<int> v[MAXN];
int a[MAXN];
void dfs(int x) {
  dp[x][1] = -0x3f3f3f3f;
  int len = v[x].size();
  if (len == 0) {
    dp[x][1] = a[x];
    dp[x][0] = 0;
    return;
  }
  for (int i = 0; i < len; i++) {
    int to = v[x][i];
    dfs(to);
    long long t0 = dp[x][0], t1 = dp[x][1];
    dp[x][1] = max(t1 + dp[to][0], t0 + dp[to][1]);
    dp[x][0] = max(t1 + dp[to][1], t0 + dp[to][0]);
  }
  dp[x][1] = max(dp[x][1], dp[x][0] + a[x]);
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int fa;
    scanf("%d%d", &fa, &a[i]);
    if (fa != -1) v[fa].push_back(i);
  }
  dfs(1);
  printf("%lld\n", dp[1][1]);
}
