#include <bits/stdc++.h>
using namespace std;
vector<int> son[200005];
int w[200005];
void init() {}
void dfs(int u, long long &odd, long long &even) {
  int len = son[u].size();
  if (len % 2 == 0) {
    even = 0;
    for (int i = 0; i < len; ++i) {
      long long o, e;
      dfs(son[u][i], o, e);
      even += o;
    }
    odd = even + w[u];
  } else {
    odd = 0;
    long long diff = 1e6;
    for (int i = 0; i < len; ++i) {
      long long o, e;
      dfs(son[u][i], o, e);
      odd += o;
      diff = min(diff, o - e);
    }
    even = odd - diff;
    odd = max(odd, even + w[u]);
  }
}
void solve() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    int u, w;
    scanf("%d%d", &u, &w);
    if (u > 0) son[u].push_back(i);
    ::w[i] = w;
  }
  long long f, g;
  dfs(1, f, g);
  cout << max(f, g) << endl;
}
int main() {
  init();
  solve();
  return 0;
}
