#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void smin(T &a, U b) {
  if (a > b) a = b;
}
template <typename T, typename U>
inline void smax(T &a, U b) {
  if (a < b) a = b;
}
inline void gn(long long &first) {
  int sg = 1;
  char c;
  while (((c = getchar()) < '0' || c > '9') && c != '-')
    ;
  c == '-' ? (sg = -1, first = 0) : (first = c - '0');
  while ((c = getchar()) >= '0' && c <= '9') first = first * 10 + c - '0';
  first *= sg;
}
inline void gn(int &first) {
  long long t;
  gn(t);
  first = t;
}
inline void gn(unsigned long long &first) {
  long long t;
  gn(t);
  first = t;
}
inline void gn(double &first) {
  double t;
  scanf("%lf", &t);
  first = t;
}
inline void gn(long double &first) {
  double t;
  scanf("%lf", &t);
  first = t;
}
inline void print(int first) {
  if (first < 10) {
    putchar(first + '0');
    return;
  }
  print(first / 10);
  putchar(first % 10 + '0');
}
int pa[201000];
long long a[201000], dp[201000][3];
vector<int> adj[201000];
int dfs(int u) {
  long long m1, m2;
  long long mx1, mx2;
  mx1 = 0, mx2 = -(1LL << 50);
  for (int i = adj[u].size(); i--;) {
    int v = adj[u][i];
    dfs(v);
    m1 = max(mx1 + dp[v][2], mx2 + max(dp[v][0], dp[v][1]));
    m2 = max(mx1 + max(dp[v][0], dp[v][1]), mx2 + dp[v][2]);
    mx1 = m1, mx2 = m2;
  }
  dp[u][0] = max(mx1 + a[u], a[u]);
  dp[u][1] = mx2;
  dp[u][2] = mx1;
  return 0;
}
int main() {
  int N, root;
  cin >> N;
  for (int i = 1, p; i <= N; i++) {
    gn(p), gn(a[i]);
    if (p < 0)
      root = i;
    else
      adj[p].push_back(i);
  }
  dfs(root);
  long long ans = 0;
  for (int i = 0; i < 3; i++) smax(ans, dp[1][i]);
  cout << ans << endl;
  return 0;
}
