#include <bits/stdc++.h>
using namespace std;
const int maxN = 2 * 1e5 + 10;
int n, a[maxN];
long long dp1[maxN], dp0[maxN], ans;
vector<int> adj[maxN];
bool mark[maxN];
void dfs(int v) {
  mark[v] = true;
  for (int i = 0; i < adj[v].size(); i++) {
    int u = adj[v][i];
    dfs(u);
    long long carry = dp0[v];
    dp0[v] = max(dp0[v] + dp0[u], dp1[v] + dp1[u]);
    dp1[v] = max(dp1[v] + dp0[u], dp1[u] + carry);
    if (i == 0) {
      dp1[v] = dp1[u];
      dp0[v] = dp0[u];
    }
  }
  dp1[v] = max(dp1[v], dp0[v] + a[v]);
  ans = max(dp1[v], dp0[v]);
}
int main() {
  cin >> n >> a[1] >> a[1];
  for (int i = 2; i <= n; i++) {
    int v;
    cin >> v >> a[i];
    adj[v].push_back(i);
  }
  dfs(1);
  cout << ans;
  return 0;
}
