#include <bits/stdc++.h>
using namespace std;
int a[200005];
long long dp[200005][2] = {}, tdp[200005][2];
vector<int> g[200005];
void dfs(int u, int par) {
  int n = g[u].size();
  for (auto v : g[u]) {
    if (v != par) dfs(v, u);
  }
  if (n == 0) return;
  memset(tdp, 0, n * 2 * sizeof(long long));
  tdp[0][0] = dp[g[u][0]][0];
  tdp[0][1] = max(dp[g[u][0]][1], dp[g[u][0]][0] + a[g[u][0]]);
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < 2; j++) {
      for (int k = 0; k < 2; k++) {
        tdp[i][j] = max(tdp[i][j], dp[g[u][i]][k] + tdp[i - 1][(j + k) & 1]);
      }
      tdp[i][j] =
          max(tdp[i][j], dp[g[u][i]][0] + tdp[i - 1][j ^ 1] + a[g[u][i]]);
    }
  }
  dp[u][0] = tdp[n - 1][0];
  dp[u][1] = tdp[n - 1][1];
}
int main() {
  int n;
  cin >> n;
  for (int i = 0, p; i < n; i++) {
    cin >> p >> a[i];
    p--;
    if (i) {
      g[p].push_back(i);
    }
  }
  dfs(0, -1);
  cout << max(dp[0][0] + a[0], dp[0][1]) << endl;
  return 0;
}
