#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
long long dp[maxn][2], t[maxn];
vector<int> g[maxn];
void DFS(int u) {
  long long a = 0, b = -1ll * maxn * maxn, A, B;
  for (int v : g[u]) {
    DFS(v);
    A = max(dp[v][0] + a, dp[v][1] + b);
    B = max(dp[v][1] + a, dp[v][0] + b);
    a = A;
    b = B;
  }
  dp[u][0] = a;
  dp[u][1] = max(b, a + t[u]);
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0, p; i < n; i++) {
    scanf("%d %d", &p, t + i);
    p--;
    if (i != 0) g[p].push_back(i);
  }
  DFS(0);
  printf("%lld", max(dp[0][0], dp[0][1]));
  return 0;
}
