#include <bits/stdc++.h>
using namespace std;
const int MaxN = 1111111;
const int INF = 0x3f3f3f3f;
int n, father[MaxN], val[MaxN];
long long dp[MaxN][2], f[MaxN][2];
vector<int> sub[MaxN];
int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    scanf("%d%d", &father[i], &val[i]);
    if (i > 1) sub[father[i]].push_back(i);
  }
  for (int i = n; i >= 1; --i) {
    f[0][0] = 0;
    f[0][1] = -1e15;
    int c = 0;
    for (auto x : sub[i]) {
      ++c;
      f[c][0] = f[c][1] = -1e15;
      for (int j = 0; j <= 1; ++j)
        for (int w = 0; w <= 1; ++w) {
          f[c][j] = max(f[c][j], (f[c - 1][j ^ w] + dp[x][w]));
        };
    }
    dp[i][0] = f[c][0];
    dp[i][1] = max(f[c][1], f[c][0] + val[i]);
  }
  cout << max(dp[1][0], dp[1][1]) << endl;
  return 0;
}
