#include <bits/stdc++.h>
using namespace std;
const long long int infinito = 1000000000000LL;
int n;
vector<int> g[1000000];
long long int a[1000000];
long long int maxpar[1000000], maximpar[1000000];
void calcula(int u) {
  vector<int> &ar = g[u];
  maximpar[u] = -infinito;
  for (int i = 0; i < int(ar.size()); i++) {
    int v = ar[i];
    calcula(v);
  }
  for (int i = 0; i < int(ar.size()); i++) {
    int v = ar[i];
    long long int nextmaxpar =
        max(maxpar[u] + maxpar[v], maximpar[u] + maximpar[v]);
    long long int nextmaximpar =
        max(maxpar[u] + maximpar[v], maximpar[u] + maxpar[v]);
    maxpar[u] = nextmaxpar;
    maximpar[u] = nextmaximpar;
  }
  maximpar[u] = max(maximpar[u], maxpar[u] + a[u]);
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int p;
    cin >> p >> a[i];
    if (p != -1) g[p].push_back(i);
  }
  calcula(1);
  cout << max(maxpar[1], maximpar[1]) << endl;
}
