#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
long long arr[N];
vector<int> adj[N];
long long dp[2][N];
void dfs(int v, int p) {
  int o = 0;
  long long maxi = -1e16;
  long long sum = 0, leaf = 1;
  for (auto c : adj[v]) {
    dfs(c, v);
    leaf = 0;
    if (dp[0][c] >= dp[1][c]) {
      sum += dp[0][c];
      maxi = max(maxi, dp[1][c] - dp[0][c]);
    } else {
      sum += dp[1][c];
      maxi = max(maxi, dp[0][c] - dp[1][c]);
      o ^= 1;
    }
  }
  dp[1][v] = sum;
  dp[0][v] = sum + maxi;
  if (!o) {
    swap(dp[1][v], dp[0][v]);
  }
  dp[1][v] = max(dp[1][v], arr[v] + dp[0][v]);
}
int main() {
  int n, p, x;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d %d", &p, &x);
    if (i != 1) adj[p].push_back(i);
    arr[i] = x;
  }
  dfs(1, 0);
  cout << max(dp[1][1], dp[0][1]) << endl;
  return 0;
}
