#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:640000000")
using namespace std;
const double eps = 1e-9;
const double pi = acos(-1.0);
const int maxn = (int)2e5 + 10;
const long long inf = (long long)1e18;
vector<int> g[maxn];
int a[maxn];
long long dp[maxn][3];
long long dd[maxn][2];
void get(int v) {
  for (int i = 0; i < (int)(g[v]).size(); i++) {
    int to = g[v][i];
    get(to);
  }
  for (int i = 0; i <= (int)(g[v]).size(); i++) {
    for (int j = 0; j < 2; j++) {
      dd[i][j] = -inf;
    }
  }
  dd[0][0] = 0;
  for (int i = 0; i < (int)(g[v]).size(); i++) {
    int to = g[v][i];
    for (int j = 0; j < 2; j++) {
      for (int k = 0; k < 2; k++) {
        dd[i + 1][j ^ k] = max(dd[i + 1][j ^ k], dd[i][j] + dp[to][k]);
      }
    }
  }
  dp[v][0] = dd[(int)(g[v]).size()][0];
  dp[v][2] = a[v] + dd[(int)(g[v]).size()][0];
  dp[v][1] = max(dd[(int)(g[v]).size()][1], dp[v][2]);
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int p;
    scanf("%d%d", &p, &a[i]);
    if (p != -1) g[p].push_back(i);
  }
  get(1);
  cout << max(dp[1][0], dp[1][1]) << endl;
  return 0;
}
