#include <bits/stdc++.h>
using namespace std;
struct data {
  long long le, chan, f;
} A[200010];
bool operator<(data a, data b) {
  if (a.le == b.le) return a.chan < b.chan;
  return a.le > b.le;
}
long long n, e[200010], dp[200010][2][2];
vector<long long> a[200010];
void dfs(long long u) {
  for (vector<long long>::iterator it = a[u].begin(); it != a[u].end(); it++) {
    long long v = *it;
    dfs(v);
  }
  long long n = 0;
  long long cnt = 0;
  for (vector<long long>::iterator it = a[u].begin(); it != a[u].end(); it++) {
    long long v = *it;
    A[++n].le = max(dp[v][1][1], dp[v][0][1]);
    A[n].chan = dp[v][0][0];
    if (A[n].le > A[n].chan) {
      A[n].f = 1;
      cnt++;
    } else
      A[n].f = 0;
  }
  if (cnt % 2 == 0) {
    for (long long i = (1), _b = (n); i <= _b; i++)
      if (A[i].f)
        dp[u][0][0] += A[i].le;
      else
        dp[u][0][0] += A[i].chan;
    for (long long i = (1), _b = (n); i <= _b; i++)
      if (A[i].f)
        dp[u][0][1] = max(dp[u][0][1], dp[u][0][0] - A[i].le + A[i].chan);
      else
        dp[u][0][1] = max(dp[u][0][1], dp[u][0][0] - A[i].chan + A[i].le);
  } else {
    for (long long i = (1), _b = (n); i <= _b; i++)
      if (A[i].f)
        dp[u][0][1] += A[i].le;
      else
        dp[u][0][1] += A[i].chan;
    for (long long i = (1), _b = (n); i <= _b; i++)
      if (A[i].f)
        dp[u][0][0] = max(dp[u][0][0], dp[u][0][1] - A[i].le + A[i].chan);
      else
        dp[u][0][0] = max(dp[u][0][0], dp[u][0][1] - A[i].chan + A[i].le);
  }
  dp[u][1][1] = dp[u][0][0] + e[u];
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n;
  for (long long i = (1), _b = (n); i <= _b; i++) {
    long long u;
    cin >> u >> e[i];
    if (u > 0) a[u].push_back(i);
  }
  dfs(1);
  cout << max(dp[1][0][0], max(dp[1][0][1], dp[1][1][1]));
  return 0;
}
