#include <bits/stdc++.h>
using namespace std;
vector<long long> ansS[2];
vector<long long> ansR;
void DFS(int R, vector<vector<int> > &son, vector<int> &eff) {
  vector<long long> eff_son;
  long long second = 0, s = 0;
  for (auto it = son[R].begin(); it != son[R].end(); it++) {
    DFS(*it, son, eff);
    second += ansS[0][*it];
    eff_son.push_back(ansS[1][*it] - ansS[0][*it]);
  }
  sort(begin(eff_son), end(eff_son));
  ansS[0][R] = second;
  int p = 0;
  for (int i = eff_son.size() - 1; i >= 0; i--) {
    s += eff_son[i];
    p++;
    ansS[p % 2][R] = max(ansS[p % 2][R], second + s);
  }
  ansR[R] = ansS[0][R] + eff[R];
  ansS[1][R] = max(ansS[1][R], ansR[R]);
  return;
}
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  int N;
  cin >> N;
  vector<int> par(N), eff(N);
  vector<vector<int> > son(N);
  ansS[0].resize(N, 0);
  ansS[1].resize(N, 0);
  ansR.resize(N, 0);
  for (int i = 0; i < N; i++) {
    cin >> par[i] >> eff[i];
    if (i > 0) son[--par[i]].push_back(i);
  }
  long long ans = 0;
  DFS(0, son, eff);
  for (int i = 0; i < N; i++) ans = max(ans, ansR[i]);
  ans = max(ans, ansS[0][0]);
  ans = max(ans, ansS[1][0]);
  cout << ans << "\n";
  return 0;
}
