#include <bits/stdc++.h>
using namespace std;
int main() {
  int parent[200010] = {0};
  int A[200010] = {0};
  int processed[200010] = {0};
  int n;
  cin >> n;
  vector<vector<int> > children(n + 1, vector<int>(0));
  for (int i = 1; i <= n; i++) {
    cin >> parent[i] >> A[i];
    if (parent[i] > 0) children[parent[i]].push_back(i);
  }
  long long total = 0;
  vector<int> stack(0);
  for (int i = 1; i <= n; i++) {
    if (children[i].size() == 0) stack.push_back(i);
  }
  while (!stack.empty()) {
    int u = stack.back();
    stack.pop_back();
    if (children[u].size() != 0) {
      int smallest = 200000;
      for (int child : children[u]) {
        total += A[child];
        if (A[child] <= smallest) smallest = A[child];
      }
      if (children[u].size() % 2 == 1) {
        total -= smallest;
        A[u] = max(A[u], smallest);
      }
    }
    int p = parent[u];
    if (p == -1) continue;
    processed[p]++;
    if (processed[p] == children[p].size()) stack.push_back(p);
  }
  total += A[1];
  cout << total << endl;
}
