#include <bits/stdc++.h>
using namespace std;
const int MAX = 4e5 + 5;
int n, a[MAX], p[MAX];
long long dp[MAX][2], f[MAX][2];
vector<int> g[MAX];
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);
  }
  for (int u = n; u > 0; u--) {
    if ((int)g[u].size() == 0) {
      dp[u][1] = a[u];
      dp[u][0] = 0;
      continue;
    }
    vector<int> e;
    e.push_back(0);
    for (int v : g[u]) e.push_back(v);
    for (int i = 0; i < (int)e.size(); i++) f[i][0] = f[i][1] = -1;
    f[0][0] = 0;
    for (int i = 1; i < (int)e.size(); i++) {
      int v = e[i];
      if (f[i - 1][0] != -1) f[i][0] = max(f[i][0], f[i - 1][0] + dp[v][0]);
      if (f[i - 1][1] != -1) f[i][0] = max(f[i][0], f[i - 1][1] + dp[v][1]);
      if (f[i - 1][0] != -1) f[i][1] = max(f[i][1], f[i - 1][0] + dp[v][1]);
      if (f[i - 1][1] != -1) f[i][1] = max(f[i][1], f[i - 1][1] + dp[v][0]);
    }
    int k = e.size() - 1;
    if (f[k][0] != -1) dp[u][0] = max(dp[u][0], f[k][0]);
    if (f[k][1] != -1) dp[u][1] = max(dp[u][1], f[k][1]);
    if (f[k][0] != -1) dp[u][1] = max(dp[u][1], f[k][0] + a[u]);
  }
  printf("%lld\n", max(dp[1][0], dp[1][1]));
  return 0;
}
