#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
int n;
vector<int> edge[300000];
long long a[300000];
long long d[300000][2];
void back(int now, int parent) {
  long long xd[2] = {0, -((1 << 30) - 1)};
  for (auto e : edge[now]) {
    if (e == parent) continue;
    back(e, now);
    long long nd[2] = {
        0,
    };
    nd[0] = max(xd[0] + d[e][1], xd[1] + d[e][0]);
    nd[1] = max(xd[1] + d[e][1], xd[0] + d[e][0]);
    xd[0] = nd[0], xd[1] = nd[1];
  }
  d[now][0] = max(xd[0] + a[now], xd[1]);
  d[now][1] = xd[0];
}
int main() {
  int i, j, k;
  cin >> n;
  for (i = 0; i < n; i++) {
    int x, y;
    scanf("%d%d", &x, &y), x--;
    a[i] = y;
    if (x == -2) continue;
    edge[x].push_back(i), edge[i].push_back(x);
  }
  back(0, -1);
  cout << max(d[0][0], d[0][1]);
  return 0;
}
