#include <bits/stdc++.h>
using namespace std;
const long long INF = 1000000000000005LL;
long long n, c[200005];
vector<long long> a[200005];
vector<long long> node;
queue<int> q;
long long res;
long long f[200005][2];
long long g[200005][2];
void bfs() {
  q.push(1);
  while (!q.empty()) {
    long long u = q.front();
    q.pop();
    node.push_back(u);
    for (long long i = 0; i < (int)a[u].size(); i++) {
      long long v = a[u][i];
      q.push(v);
    }
  }
}
long long cal(long long u, long long type) {
  long long m = (long long)a[u].size();
  g[m][0] = 0;
  g[m][1] = -INF;
  for (long long i = m - 1; i >= 0; i--) {
    long long v = a[u][i];
    for (long long j = 0; j <= 1; j++) {
      g[i][j] = max(g[i + 1][j] + f[v][0], g[i + 1][(j + 1) % 2] + f[v][1]);
    }
  }
  return g[0][type];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    long long x;
    cin >> x >> c[i];
    if (x != -1) a[x].push_back(i);
  }
  bfs();
  for (long long i = n - 1; i >= 0; i--) {
    long long u = node[i];
    f[u][0] = cal(u, 0);
    f[u][1] = max(cal(u, 1), cal(u, 0) + c[u]);
  }
  cout << max(f[1][0], f[1][1]) << "\n";
  return 0;
}
