#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 7;
int n;
long long a[maxn];
vector<int> adj[maxn];
long long dp[maxn][2];
const long long inf = 1e13;
void go(int u) {
  long long res = 0;
  long long _min = inf;
  for (int v : adj[u]) {
    go(v);
    assert(dp[v][1] >= dp[v][0]);
    _min = min(_min, dp[v][1] - dp[v][0]);
    res += dp[v][1];
  }
  if (adj[u].size() % 2) {
    dp[u][0] = res - _min;
    dp[u][1] = max(dp[u][0] + a[u], res);
  } else {
    dp[u][0] = res;
    dp[u][1] = max(dp[u][0] + a[u], res - _min);
  }
}
int main() {
  cin >> n;
  int root;
  for (int i = 1; i <= n; i++) {
    int p;
    scanf("%d %lld", &p, &a[i]);
    if (p == -1)
      root = i;
    else
      adj[p].push_back(i);
  }
  go(root);
  cout << dp[root][1] << endl;
  return 0;
}
