#include <bits/stdc++.h>
using namespace std;
struct edges {
  int to, next;
};
edges edge[400010];
int n, head[200010], num;
int ru[200010];
long long dp[200010][3], efficiency[200010];
int root;
bool vis[200010];
void add(int u, int v) {
  num++;
  edge[num].to = v;
  edge[num].next = head[u];
  head[u] = num;
}
void dfs(int now) {
  int i;
  vis[now] = 1;
  if (ru[now] == 1) {
    dp[now][1] = efficiency[now];
    dp[now][0] = 0;
    return;
  }
  dp[now][1] = -1e18;
  dp[now][0] = 0;
  for (i = head[now]; i != 0; i = edge[i].next) {
    int v = edge[i].to;
    if (vis[v] == 1) continue;
    dfs(v);
    long long flag = dp[now][1], cnt = dp[now][0];
    dp[now][1] = max(cnt + dp[v][1], flag + dp[v][0]);
    dp[now][0] = max(cnt + dp[v][0], flag + dp[v][1]);
  }
  dp[now][1] = max(dp[now][1], dp[now][0] + efficiency[now]);
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  int i;
  cin >> n;
  for (i = 1; i <= n; i++) {
    int v;
    cin >> v >> efficiency[i];
    ru[i]++;
    ru[v]++;
    if (v == -1) {
      root = i;
      continue;
    }
    add(i, v);
    add(v, i);
  }
  dfs(root);
  cout << dp[root][1] << endl;
  return 0;
}
