#include <bits/stdc++.h>
using namespace std;
bool vis[200010];
std::vector<int> adj[200010], st;
long long ans[200010], value[200010], maxx[200010], dp[200010][2];
void dfs(int v) {
  if (vis[v]) return;
  vis[v] = 1;
  for (int i = 0; i < adj[v].size(); i++) dfs(adj[v][i]);
  st.push_back(v);
}
int main() {
  int n, i, curr, temp1, temp2, j;
  long long mini, answer = 0;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d", &temp1);
    scanf("%d", &temp2);
    if (i > 1) adj[temp1].push_back(i);
    value[i] = temp2;
  }
  dfs(1);
  long long tmp1, tmp2;
  for (i = 0; i < st.size(); i++) {
    curr = st[i];
    if (adj[curr].size())
      dp[curr][1] = dp[adj[curr][0]][1], dp[curr][0] = dp[adj[curr][0]][0];
    for (j = 1; j < adj[curr].size(); j++) {
      tmp1 = max(dp[curr][1] + dp[adj[curr][j]][1],
                 dp[curr][0] + dp[adj[curr][j]][0]);
      tmp2 = max(dp[curr][1] + dp[adj[curr][j]][0],
                 dp[curr][0] + dp[adj[curr][j]][1]);
      dp[curr][0] = tmp1;
      dp[curr][1] = tmp2;
    }
    dp[curr][1] = max(dp[curr][1], dp[curr][0] + value[curr]);
  }
  printf("%I64d\n", max(dp[1][0], dp[1][1]));
}
