#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void smin(T &a, U b) {
  if (a > b) a = b;
}
template <typename T, typename U>
inline void smax(T &a, U b) {
  if (a < b) a = b;
}
vector<int> adj[200200];
int p[200200], a[200200];
long long dp[200200][4], tmp[4];
const long long inf = 10000000000000LL;
void dfs(int u) {
  dp[u][0] = 0;
  dp[u][1] = -inf;
  dp[u][2] = -inf;
  dp[u][3] = a[u];
  for (int i = adj[u].size(); i--;) {
    int v = adj[u][i];
    dfs(v);
    memcpy(tmp, dp[u], sizeof(dp[u]));
    dp[u][0] = max(tmp[0] + dp[v][0], tmp[1] + max(dp[v][1], dp[v][3]));
    dp[u][1] = max(tmp[0] + max(dp[v][1], dp[v][3]), tmp[1] + dp[v][0]);
    dp[u][2] = max(tmp[2] + dp[v][0], tmp[3] + max(dp[v][1], dp[v][3]));
    dp[u][3] = max(tmp[2] + max(dp[v][1], dp[v][3]), tmp[3] + dp[v][0]);
  }
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    scanf("%d %d", p + i, a + i);
    if (i == 1) continue;
    adj[p[i]].push_back(i);
  }
  dfs(1);
  cout << max(dp[1][0], max(dp[1][1], dp[1][3])) << endl;
  return 0;
}
