#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200007;
vector<int> g[MAXN];
long long dp[MAXN][2], a[MAXN];
void calc(int cur) {
  long long odd, even, new_odd, new_even;
  int i;
  if (!g[cur].size()) {
    dp[cur][0] = 0;
    dp[cur][1] = a[cur];
    return;
  }
  calc(g[cur][0]);
  even = dp[g[cur][0]][0];
  odd = dp[g[cur][0]][1];
  for (i = 1; i < g[cur].size(); i++) {
    calc(g[cur][i]);
    new_odd = max(even + dp[g[cur][i]][1], odd + dp[g[cur][i]][0]);
    new_even = max(even + dp[g[cur][i]][0], odd + dp[g[cur][i]][1]);
    even = new_even;
    odd = new_odd;
  }
  dp[cur][0] = even;
  dp[cur][1] = max(odd, a[cur] + even);
}
int main() {
  ios_base::sync_with_stdio(false);
  int n, i, p;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> p >> a[i];
    if (p == -1) continue;
    g[p].push_back(i);
  }
  memset(dp, 0, sizeof(dp));
  calc(1);
  cout << max(dp[1][0], dp[1][1]) << endl;
  return 0;
}
