#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
vector<int> v[N];
long long dp[N][4];
int a[N];
void dfs(int u, int pre) {
  long long odd = -1LL << 60, even = 0;
  for (int i = 0; i < v[u].size(); i++) {
    int x = v[u][i];
    if (x == pre) continue;
    dfs(x, u);
    long long t1 = odd, t2 = even;
    t1 = max(even + dp[x][0], odd + dp[x][1]);
    t2 = max(odd + dp[x][0], even + dp[x][1]);
    odd = t2, even = t1;
  }
  dp[u][0] = even;
  dp[u][1] = max(odd, a[u] + even);
}
int main() {
  int n;
  int root;
  scanf("%d", &n);
  int x, y;
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &x, &a[i]);
    if (x == -1)
      root = i;
    else
      v[x].push_back(i);
  }
  dfs(root, -1);
  cout << max(dp[root][0], dp[root][1]) << endl;
  return 0;
}
