#include <bits/stdc++.h>
const int N = 1000050;
using namespace std;
inline int gi() {
  register char ch = getchar();
  register int x = 0, q = 0;
  while (ch < '0' || ch > '9') ch == '-' ? q = 1 : 0, ch = getchar();
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return q ? (-x) : x;
}
int nn[N][2], head[N], a[N], cnt;
long long f[N][2], p[2];
inline void dfs(int x, int fa) {
  f[x][1] = -1e9;
  for (register int i = head[x], y; y = nn[i][1], i; i = nn[i][0])
    if (y != fa) {
      dfs(y, x), p[0] = f[x][0], p[1] = f[x][1];
      f[x][0] = (f[x][0] > p[1] + f[y][1] ? f[x][0] : p[1] + f[y][1]);
      f[x][0] = (f[x][0] > p[0] + f[y][0] ? f[x][0] : p[0] + f[y][0]);
      f[x][1] = (f[x][1] > p[0] + f[y][1] ? f[x][1] : p[0] + f[y][1]);
      f[x][1] = (f[x][1] > p[1] + f[y][0] ? f[x][1] : p[1] + f[y][0]);
      f[x][0] =
          (f[x][0] > f[y][0] + a[y] + p[1] ? f[x][0] : f[y][0] + a[y] + p[1]);
      f[x][1] =
          (f[x][1] > f[y][0] + a[y] + p[0] ? f[x][1] : f[y][0] + a[y] + p[0]);
    }
  return;
}
int main() {
  register int n = gi(), i, u = gi();
  a[1] = gi();
  if (a[1] < 0) a[1] = 0;
  for (i = 2; i <= n; ++i)
    u = gi(), a[i] = gi(),
    (nn[++cnt][1] = i, nn[cnt][0] = head[u], head[u] = cnt);
  dfs(1, 0);
  long long ans = (f[1][0] + a[1] > f[1][1] ? f[1][0] + a[1] : f[1][1]);
  cout << ans;
  return 0;
}
