#include <bits/stdc++.h>
using namespace std;
long long v[200005];
vector<int> G[200005];
long long dp[2];
void dfs(int u, int fa) {
  long long te[2];
  te[0] = 0;
  te[1] = -1000000000000000LL;
  for (int i = 0; i < G[u].size(); i++)
    if (fa != G[u][i]) {
      int v = G[u][i];
      dfs(v, u);
      long long a = max(te[1] + dp[1], te[0] + dp[0]);
      long long b = max(te[0] + dp[1], te[1] + dp[0]);
      te[0] = a;
      te[1] = b;
    }
  dp[0] = te[0];
  dp[1] = max(te[1], te[0] + v[u]);
}
int main() {
  int n, x, y;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%I64d", &x, &v[i]);
    if (x == -1) y = i;
    G[x].push_back(i);
  }
  dfs(y, -1);
  cout << dp[1] << endl;
}
