#include <bits/stdc++.h>
using namespace std;
vector<int> adj[200010];
int val[200010];
long long ans[200010][3];
inline void dfs(int u) {
  long long temp[2] = {0, 0};
  for (int i = 0; i < adj[u].size(); i++) {
    int v = adj[u][i];
    dfs(v);
    if (i) {
      long long t0, t1;
      t0 = max(temp[0] + ans[v][0], temp[1] + max(ans[v][2], ans[v][1]));
      t1 = max(temp[1] + ans[v][0], temp[0] + max(ans[v][2], ans[v][1]));
      temp[0] = t0;
      temp[1] = t1;
    } else {
      temp[0] = ans[v][0];
      temp[1] = max(ans[v][1], ans[v][2]);
    }
  }
  ans[u][0] = temp[0];
  ans[u][1] = temp[1];
  ans[u][2] = temp[0] + val[u];
}
int main() {
  int n, p, root;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &p, val + i);
    if (p == -1) {
      root = i;
      continue;
    }
    adj[p].push_back(i);
  }
  dfs(root);
  long long res = 0;
  for (int i = 0; i < 3; i++) res = max(res, ans[root][i]);
  cout << res << endl;
  return 0;
}
