#include <bits/stdc++.h>
using namespace std;
const long long INF = 1000000000000LL;
const int mod = 1e9 + 7;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int maxn = 2e5 + 5;
vector<int> G[maxn];
long long dp1[maxn][2], dp2[maxn][2], e[maxn];
void dfs(int cur, int fa) {
  dp1[cur][0] = e[cur];
  dp1[cur][1] = -INF;
  dp2[cur][0] = 0;
  dp2[cur][1] = -INF;
  for (int i = 0; i < G[cur].size(); i++) {
    int nt = G[cur][i];
    if (nt == fa) continue;
    dfs(nt, cur);
    long long temp1 = dp1[cur][0], temp2 = dp1[cur][1];
    long long temp3 = dp2[cur][0], temp4 = dp2[cur][1];
    dp2[cur][0] = max(dp2[cur][0], temp3 + dp2[nt][0]);
    dp2[cur][0] = max(dp2[cur][0], temp4 + dp2[nt][1]);
    dp2[cur][0] = max(dp2[cur][0], temp4 + dp1[nt][0]);
    dp2[cur][1] = max(dp2[cur][1], temp3 + dp2[nt][1]);
    dp2[cur][1] = max(dp2[cur][1], temp4 + dp2[nt][0]);
    dp2[cur][1] = max(dp2[cur][1], temp3 + dp1[nt][0]);
    dp1[cur][0] = max(dp1[cur][0], temp2 + dp1[nt][0]);
    dp1[cur][0] = max(dp1[cur][0], temp1 + dp2[nt][0]);
    dp1[cur][0] = max(dp1[cur][0], temp2 + dp2[nt][1]);
    dp1[cur][1] = max(dp1[cur][1], temp1 + dp1[nt][0]);
    dp1[cur][1] = max(dp1[cur][1], temp2 + dp2[nt][0]);
    dp1[cur][1] = max(dp1[cur][1], temp1 + dp2[nt][1]);
  }
}
int main() {
  int n, p;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d %lld", &p, &e[i]);
    if (i != 1) {
      G[p].push_back(i);
      G[i].push_back(p);
    }
  }
  dfs(1, 0);
  long long res = -1LL;
  for (int i = 1; i <= n; i++) {
    res = max(res, dp1[i][0]);
    res = max(res, dp2[i][0]);
    res = max(res, dp2[i][1]);
  }
  printf("%lld\n", res);
  return 0;
}
