#include <bits/stdc++.h>
using namespace std;
const int N = int(3e5), mod = int(1e9) + 7;
int n, a[N], p[N];
long long dp[N][3];
vector<int> g[N];
void dfs(int v) {
  int sz = g[v].size();
  long long d[sz + 2][3];
  for (int i = 0; i < sz; i++) {
    int to = g[v][i];
    dfs(to);
    if (i == 0) {
      d[i][0] = dp[to][0];
      d[i][1] = dp[to][1];
    } else {
      d[i][0] = max(d[i - 1][1] + dp[to][1], d[i - 1][0] + dp[to][0]);
      d[i][1] = max(d[i - 1][0] + dp[to][1], d[i - 1][1] + dp[to][0]);
    }
  }
  if (sz == 0) {
    dp[v][0] = 0;
    dp[v][1] = a[v];
  } else {
    dp[v][0] = d[sz - 1][0];
    dp[v][1] = max(d[sz - 1][1], d[sz - 1][0] + a[v]);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &p[i], &a[i]);
    if (i > 1) g[p[i]].push_back(i);
  }
  dfs(1);
  printf("%lld", max(dp[1][0], dp[1][1]));
  return 0;
}
