#include <bits/stdc++.h>
using namespace std;
const long long maxn = 2e5 + 10;
vector<long long> g[maxn];
long long dp[maxn][2];
long long val[maxn];
void dfs(long long u) {
  for (long long i = 0; i < g[u].size(); i++) {
    long long v = g[u][i];
    dfs(v);
  }
  dp[u][0] = 0;
  dp[u][1] = -0x3f3f3f3f;
  long long tmp0 = 0;
  long long las0 = 0, las1 = -0x3f3f3f3f;
  long long tmp1 = dp[u][1];
  for (long long i = 0; i < g[u].size(); i++) {
    long long v = g[u][i];
    tmp0 = max(las0 + dp[v][0], las1 + dp[v][1]);
    tmp1 = max(las1 + dp[v][0], las0 + dp[v][1]);
    ;
    las0 = tmp0, las1 = tmp1;
  }
  dp[u][0] = tmp0;
  dp[u][1] = max(tmp1, tmp0 + val[u]);
}
int main() {
  long long n;
  cin >> n;
  long long rt;
  for (long long i = 1; i <= n; i++) {
    long long a, b;
    cin >> a >> b;
    if (a == -1) {
      val[i] = b;
      rt = i;
      continue;
    }
    g[a].push_back(i);
    val[i] = b;
  }
  dfs(rt);
  cout << dp[rt][1] << endl;
}
