#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
vector<vector<int> > G;
long long pr[2 * 100005], dp[2 * 100005][2];
void dfs(int c) {
  int child;
  long long t1, t2;
  for (int i = 0; i < G[c].size(); ++i) {
    dfs(G[c][i]);
  }
  if (G[c].size()) {
    child = G[c][0];
    dp[c][0] = dp[child][0], dp[c][1] = dp[child][1];
  }
  for (int i = 1; i < G[c].size(); ++i) {
    child = G[c][i];
    t1 = max(dp[child][0] + dp[c][0], dp[child][1] + dp[c][1]);
    t2 = max(dp[child][1] + dp[c][0], dp[child][0] + dp[c][1]);
    dp[c][0] = t1;
    dp[c][1] = t2;
  }
  dp[c][1] = max(dp[c][0] + pr[c], dp[c][1]);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.precision(10);
  cout << fixed;
  int n, a, p;
  cin >> n;
  G.resize(n + 1);
  cin >> p >> a;
  pr[1] = (long long)a;
  for (int i = 2; i <= n; ++i) {
    cin >> p >> a;
    pr[i] = (long long)a;
    G[p].push_back(i);
  }
  dfs(1);
  cout << max(dp[1][0], dp[1][1]) << '\n';
  return 0;
}
