#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream& operator<<(ostream& o, const pair<T, U>& v) {
  return o << "(" << v.first << ", " << v.second << ")";
}
template <class T>
ostream& operator<<(ostream& o, const vector<T>& v) {
  o << "{";
  for (int i = 0; i < (int)((int)((v).size())); ++i)
    o << (i ? ", " : "") << v[i];
  return o << "}";
}
template <class T, class U>
ostream& operator<<(ostream& o, const map<T, U>& v) {
  o << "{";
  for (const auto& e : v) o << e << ", ";
  return o << "}";
}
template <class T>
string to_s(const T& v) {
  ostringstream is;
  is << v;
  return is.str();
}
const int dx[] = {0, -1, 0, 1};
const int dy[] = {-1, 0, 1, 0};
const int MAX_N = 2e5;
int a[MAX_N];
vector<int> G[MAX_N];
pair<long long, long long> dp[MAX_N];
pair<long long, long long> rec(int v) {
  if (dp[v].first >= 0) return dp[v];
  pair<long long, long long> ret(0, 0);
  bool t = false;
  for (auto e : G[v]) {
    auto p = rec(e);
    if (t)
      ret = make_pair(max(ret.first + p.second, ret.second + p.first),
                      max(ret.first + p.first, ret.second + p.second));
    else
      ret = p;
    t = true;
  }
  if (t)
    ret.first = max(ret.first, ret.second + a[v]);
  else
    ret = make_pair(a[v], 0);
  return dp[v] = ret;
}
int main(int argc, char* argv[]) {
  int n;
  cin >> n;
  for (int i = 0; i < (int)(n); ++i) {
    int p;
    cin >> p >> a[i];
    if (p != -1) G[p - 1].push_back(i);
  }
  long long ans = 0;
  memset(dp, -1, sizeof(dp));
  for (int i = 0; i < (int)(n); ++i) {
    auto e = rec(i);
    ans = max(ans, max(e.first, e.second));
  }
  cout << ans << '\n';
  return 0;
}
