#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int mm = 200005;
vector<int> G[mm];
int f[mm], e[mm];
long long dp0[mm], dp1[mm];
void dfs(int rt) {
  long long pre0 = 0, pre1 = -1e10;
  for (int i = 0; i < G[rt].size(); i++) {
    int &u = G[rt][i];
    dfs(u);
    dp0[rt] = max(pre0 + dp0[u], dp1[u] + pre1);
    dp1[rt] = max(pre1 + dp0[u], dp1[u] + pre0);
    pre0 = dp0[rt];
    pre1 = dp1[rt];
  }
  dp0[rt] = pre0, dp1[rt] = max(pre1, pre0 + e[rt]);
}
int main() {
  int n;
  while (cin >> n) {
    for (int i = 0; i <= n; i++) G[i].clear();
    for (int i = 1; i <= n; i++) {
      scanf("%d%d", f + i, e + i);
      if (f[i] >= 0) G[f[i]].push_back(i);
    }
    dfs(1);
    cout << dp1[1] << endl;
  }
  return 0;
}
