#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
const long long Mod = 1e9 + 7;
const long double pai = acos(-1);
long long n;
vector<long long> v[200009];
long long val[200009], dp[200009][2];
void dfs(long long node) {
  dp[node][1] = -inf;
  for (auto u : v[node]) {
    dfs(u);
    long long Dp0 = dp[node][0], Dp1 = dp[node][1];
    dp[node][0] = max(Dp0 + dp[u][0], Dp1 + dp[u][1]);
    dp[node][1] = max(Dp0 + dp[u][1], Dp1 + dp[u][0]);
  }
  dp[node][1] = max(dp[node][1], dp[node][0] + val[node]);
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    int b = i, a;
    cin >> a, a--;
    cin >> val[i];
    if (a < 0) continue;
    v[a].push_back(b);
  }
  dfs(0);
  cout << max(dp[0][0], dp[0][1]) << endl;
}
