#include <bits/stdc++.h>
#pragma GCC optimize "-O3"
using namespace std;
const int MX = 200 * 1000 + 7;
const long long INF = 1e18;
vector<int> g[MX];
long long a[MX];
long long f[MX][2];
void dfs(int v) {
  f[v][1] = -INF;
  for (int to : g[v]) {
    dfs(to);
    long long g0 = max(f[v][0] + f[to][0], f[v][1] + f[to][1]);
    long long g1 = max(f[v][1] + f[to][0], f[v][0] + f[to][1]);
    f[v][0] = g0;
    f[v][1] = g1;
  }
  f[v][1] = max(f[v][1], f[v][0] + a[v]);
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  int root = -1;
  for (int i = 1; i <= n; i++) {
    int p;
    cin >> p >> a[i];
    if (p == -1) {
      root = i;
    } else {
      g[p].push_back(i);
    }
  }
  dfs(root);
  cout << max(f[root][0], f[root][1]) << "\n";
  return 0;
}
