#include <bits/stdc++.h>
using namespace std;
int N;
vector<int> E[202000];
int P[202000];
signed long long A[202000];
signed long long T[2][202000];
signed long long ma;
void solve() {
  int i, j, k, l, r, x, y;
  string s;
  cin >> N;
  for (i = 0; i < N; i++) cin >> P[i] >> A[i];
  for (i = 1; i < N; i++) E[P[i] - 1].push_back(i);
  for (i = N - 1; i >= 0; i--) {
    T[1][i] = -1LL << 60;
    for (auto& r : E[i]) {
      signed long long p0 = T[0][i], p1 = T[1][i];
      T[0][i] = max(p0 + T[0][r], p1 + T[1][r]);
      T[1][i] = max(p1 + T[0][r], p0 + T[1][r]);
    }
    T[1][i] = max(T[1][i], T[0][i] + A[i]);
  }
  cout << max(T[0][0], T[1][0]) << endl;
}
int main(int argc, char** argv) {
  string s;
  int i;
  if (argc == 1) ios::sync_with_stdio(false);
  for (i = 0; i < argc - 1; i++) s += argv[i + 1], s += '\n';
  for (i = 0; i < s.size(); i++) ungetc(s[s.size() - 1 - i], stdin);
  solve();
  return 0;
}
