#include <bits/stdc++.h>
using namespace std;
long long f[210000][2];
int last[210000], pre[410000], e[410000], a[210000], pp[210000];
int n, root, x, y, num;
void dfs(int x) {
  pp[x] = 1;
  f[x][1] = -1e15;
  for (int i = last[x]; i; i = pre[i]) {
    if (!pp[e[i]]) {
      dfs(e[i]);
      long long b = f[x][0], c = f[x][1];
      f[x][0] = max(b + f[e[i]][0], c + f[e[i]][1]);
      f[x][1] = max(b + f[e[i]][1], c + f[e[i]][0]);
    }
  }
  f[x][1] = max(f[x][1], f[x][0] + (long long)a[x]);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d %d", &x, &a[i]);
    if (x == -1)
      root = i;
    else
      e[++num] = i, pre[num] = last[x], last[x] = num;
  }
  dfs(root);
  cout << max(f[root][0], f[root][1]) << endl;
  return 0;
}
