#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int N = 2e5 + 5;
int eff[N], n;
long long dp[N][2];
vector<int> v1[N];
void dfs(int node, int par) {
  dp[node][1] = -INT_MAX;
  for (auto it : v1[node])
    if (it != par) {
      dfs(it, node);
      long long val0 = dp[node][0], val1 = dp[node][1];
      dp[node][0] = max(val0 + dp[it][0], val1 + dp[it][1]);
      dp[node][1] = max(val0 + dp[it][1], val1 + dp[it][0]);
    }
  dp[node][1] = max(dp[node][1], dp[node][0] + eff[node]);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n + 1; i++) {
    int par;
    scanf("%d %d", &par, &eff[i]);
    if (par == -1) continue;
    v1[par].push_back(i);
    v1[i].push_back(par);
  }
  dfs(1, -1);
  printf("%lld\n", dp[1][1]);
}
