#include <bits/stdc++.h>
using namespace std;
inline int in() {
  int x;
  scanf("%d", &x);
  return x;
}
inline void priv(vector<int>& a) {
  for (int i = 0; i < (int)(a).size(); ++i)
    printf("%d%c", a[i], i == (int)(a).size() - 1 ? '\n' : ' ');
}
const int MX = 200005, INF = 1000010000;
const long long int LINF = 1000000000000000000ll;
const double eps = 1e-10;
const int di[] = {-1, 0, 1, 0}, dj[] = {0, -1, 0, 1};
vector<int> to[MX];
int a[MX];
vector<long long int> dp[MX];
void dfs(int v) {
  dp[v] = vector<long long int>(2);
  dp[v][1] = -LINF;
  for (int u : to[v]) {
    dfs(u);
    vector<long long int> p = dp[v];
    for (int i = 0; i < 2; ++i)
      for (int j = 0; j < 2; ++j) {
        dp[v][i ^ j] = max(dp[v][i ^ j], p[i] + dp[u][j]);
      }
  }
  dp[v][1] = max(dp[v][1], dp[v][0] + a[v]);
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    int p;
    scanf("%d%d", &p, &a[i]);
    p--;
    if (i) to[p].push_back(i);
  }
  dfs(0);
  cout << max(dp[0][0], dp[0][1]) << endl;
  return 0;
}
