#include <bits/stdc++.h>
using namespace std;
vector<int> tree[2 * 100000 + 4];
long long dp[2 * 100000 + 3][2];
int value[2 * 100000 + 4];
void dfs(int x) {
  dp[x][0] = 0;
  dp[x][1] = -200000000005;
  for (int i = 0, sz = tree[x].size(); i < sz; i++) {
    int v = tree[x][i];
    dfs(v);
    long long tmp1 = dp[x][1], tmp0 = dp[x][0];
    dp[x][0] = max(tmp0 + dp[v][0], tmp1 + dp[v][1]);
    dp[x][1] = max(tmp1 + dp[v][0], tmp0 + dp[v][1]);
  }
  dp[x][1] = max(dp[x][0] + value[x], dp[x][1]);
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x >> value[i];
    if (i == 1) continue;
    tree[x].push_back(i);
  }
  dfs(1);
  cout << max(dp[1][0], dp[1][1]) << endl;
}
