#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << '\n';
  err(++it, args...);
}
long long MOD = 1000000009;
long long int n;
vector<vector<long long int>> adj;
vector<long long int> val;
long long int dp[200010][2];
void dfs(long long int nn, long long int par) {
  dp[nn][0] = 0;
  dp[nn][1] = val[nn];
  long long int temp[2][2];
  long long int cnt = 0;
  memset(temp, 0, sizeof(temp));
  for (auto i : adj[nn]) {
    if (i != par) {
      cnt++;
      dfs(i, nn);
      if (cnt == 1) {
        temp[0][0] = dp[i][0];
        temp[0][1] = dp[i][1];
      } else {
        long long int now = 1 - (cnt % 2);
        long long int prev = cnt % 2;
        temp[1 - (cnt % 2)][0] =
            max(temp[prev][0] + dp[i][0], temp[prev][1] + dp[i][1]);
        temp[now][1] = max(temp[prev][0] + dp[i][1], temp[prev][1] + dp[i][0]);
      }
    }
  }
  if (cnt != 0) {
    dp[nn][0] = temp[1 - (cnt % 2)][0];
    dp[nn][1] = max(temp[1 - (cnt % 2)][0] + val[nn], temp[1 - (cnt % 2)][1]);
  }
}
void solve() {
  cin >> n;
  adj.resize(n + 1);
  val.resize(n + 1);
  for (long long int i = 0; i < (n); i++) {
    long long int p, v;
    cin >> p >> v;
    if (p != -1) {
      adj[p].push_back(i + 1);
    }
    val[i + 1] = v;
  }
  memset(dp, 0, sizeof(dp));
  dfs(1, 0);
  long long int ans = max(dp[1][0] + val[1], dp[1][1]);
  cout << ans << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
}
