#include <bits/stdc++.h>
using namespace std;
const long long inf = 2e5 + 9, MX = 1e13 + 9;
long long val[inf], dp[inf][2], n;
vector<long long> v[inf];
void dfs(long long node, long long par) {
  dp[node][1] = -MX;
  for (auto o : v[node]) {
    if (o == par) continue;
    dfs(o, node);
    long long x = dp[node][0], y = dp[node][1];
    dp[node][0] = max(x + dp[o][0], y + dp[o][1]);
    dp[node][1] = max(x + dp[o][1], y + dp[o][0]);
  }
  long long x = dp[node][0], y = dp[node][1];
  dp[node][1] = max(dp[node][1], dp[node][0] + val[node]);
}
int main() {
  long long a;
  cin >> n >> a >> val[1];
  for (long long i = 2; i <= n; i++) {
    cin >> a >> val[i];
    v[a].push_back(i);
  }
  dfs(1, 0);
  cout << max(dp[1][0], dp[1][1]) << endl;
}
