#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
vector<int> gr[N];
int a[N];
long long dp[N][2];
int ans[N];
void dfs(int head, int par) {
  dp[head][1] = LLONG_MIN;
  for (auto x : gr[head]) {
    if (x != par) {
      dfs(x, head);
      long long x0 = dp[head][0];
      long long x1 = dp[head][1];
      dp[head][1] = max(x0 + dp[x][1], x1 + dp[x][0]);
      dp[head][0] = max(x0 + dp[x][0], x1 + dp[x][1]);
    }
  }
  dp[head][1] = max(dp[head][1], dp[head][0] + a[head]);
}
int main() {
  int n;
  scanf("%d", &n);
  int head;
  for (int i = 1; i <= n; i++) {
    int p;
    scanf("%d %d", &p, a + i);
    if (p == -1) {
      head = i;
    } else {
      gr[i].push_back(p);
      gr[p].push_back(i);
    }
  }
  dfs(head, 0);
  printf("%lld", dp[head][1]);
  return 0;
}
