#include <bits/stdc++.h>
using namespace std;
template <typename T>
void maxE(T& a, const T& b) {
  a = max(a, b);
}
template <typename T>
void minE(T& a, const T& b) {
  a = min(a, b);
}
template <typename T>
ostream& operator<<(ostream& out, const vector<T>& t_) {
  out << "[";
  for (auto i : t_) out << i << ", ";
  out << "]";
  return out;
}
template <typename S, typename T>
ostream& operator<<(ostream& out, const pair<S, T>& rhs) {
  out << "(" << rhs.first << "," << rhs.second << ")";
  return out;
}
const int MAXN = 200100;
const long long INF = 1000LL * 1000 * 1000 * 1000 * 1000 * 1000;
int n;
long long t[MAXN][2];
vector<int> ch[MAXN];
int p[MAXN];
int eff[MAXN];
long long dp[MAXN][2];
void solve(int a) {
  for (auto i : ch[a]) solve(i);
  {
    dp[0][0] = 0;
    dp[0][1] = -INF;
    for (int i = 0; i < int(((int)((ch[a]).size()))); ++i) {
      int c = ch[a][i];
      dp[i + 1][0] = max(dp[i][0] + t[c][0], dp[i][1] + t[c][1]);
      dp[i + 1][1] = max(dp[i][0] + t[c][1], dp[i][1] + t[c][0]);
    }
    for (int i = 0; i < int(2); ++i) t[a][i] = dp[((int)((ch[a]).size()))][i];
  }
  {
    dp[0][0] = -INF;
    dp[0][1] = eff[a];
    for (int i = 0; i < int(((int)((ch[a]).size()))); ++i) {
      int c = ch[a][i];
      dp[i + 1][0] = max(dp[i][0] + t[c][0], dp[i][1] + t[c][1]);
      dp[i + 1][1] = max(dp[i][0] + t[c][1], dp[i][1] + t[c][0]);
    }
    maxE(t[a][1], dp[((int)((ch[a]).size()))][1]);
  }
  if (0)
    cout << "a"
         << " " << a << " "
         << "t[a][0]"
         << " " << t[a][0] << " "
         << "t[a][1]"
         << " " << t[a][1] << " " << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  assert(scanf("%d", &n) == 1);
  for (int i = 0; i < int(n); ++i) {
    assert(scanf("%d%d", p + i, eff + i) == 2);
    p[i]--;
    ch[p[i]].push_back(i);
  }
  solve(0);
  cout << max(t[0][0], t[0][1]) << endl;
  return 0;
}
