#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > graph;
long long val[2][200005], ara[200005];
void solve(int now) {
  if (!graph[now].size()) {
    val[0][now] = 0;
    val[1][now] = ara[now];
    return;
  }
  long long maximum[2], total_max = 0, diff = 10000000000000000ll;
  int i, turn = 0;
  for (i = 0; i < graph[now].size(); i++) {
    solve(graph[now][i]);
    if (val[0][graph[now][i]] > val[1][graph[now][i]]) {
      total_max += val[0][graph[now][i]];
      if (val[0][graph[now][i]] - val[1][graph[now][i]] < diff)
        diff = val[0][graph[now][i]] - val[1][graph[now][i]];
    } else {
      total_max += val[1][graph[now][i]];
      turn++;
      if (val[1][graph[now][i]] - val[0][graph[now][i]] < diff)
        diff = val[1][graph[now][i]] - val[0][graph[now][i]];
    }
  }
  turn %= 2;
  maximum[turn] = total_max;
  maximum[!turn] = total_max - diff;
  val[1][now] = max(maximum[0] + ara[now], maximum[1]);
  val[0][now] = maximum[0];
  return;
}
int main() {
  int n;
  scanf("%d", &n);
  int i;
  vector<int> temp;
  for (i = 0; i < n; i++) graph.push_back(temp);
  for (i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    scanf("%I64d", &ara[i]);
    if (x != -1) {
      graph[x - 1].push_back(i);
    }
  }
  solve(0);
  cout << max(val[0][0], val[1][0]) << endl;
  return 0;
}
