#include <bits/stdc++.h>
using namespace std;
const int maxN = 2e5 + 100;
const long long inf = 1e16;
long long f[maxN][2];
vector<int> ke[maxN];
int a[maxN], n;
long long ans = 0;
void dq(int u) {
  for (int i = 0; i < ke[u].size(); i++) dq(ke[u][i]);
  f[u][1] = -inf;
  long long f0, f1;
  for (int i = 0; i < ke[u].size(); i++) {
    f0 = max(f[ke[u][i]][0] + f[u][0], f[ke[u][i]][1] + f[u][1]);
    f1 = max(f[ke[u][i]][1] + f[u][0], f[ke[u][i]][0] + f[u][1]);
    f[u][0] = f0;
    f[u][1] = f1;
  }
  f0 = (f[u][0]);
  f1 = max(f[u][0] + a[u], f[u][1]);
  ans = max(ans, f[u][1]);
  f[u][0] = f0;
  f[u][1] = f1;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int u;
    scanf("%i%i", &u, &a[i]);
    u = max(u, 0);
    ke[u].push_back(i);
  }
  dq(0);
  for (int i = 1; i <= n; i++) ans = max(ans, f[i][1]);
  cout << ans;
  return 0;
}
