#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200005;
const int MAXE = 200005;
const long long INF = 1e18;
struct Edge {
  int v, n;
  Edge() {}
  Edge(int v, int n) : v(v), n(n) {}
};
Edge E[MAXE];
int H[MAXN], cntE;
int val[MAXN];
long long dp[MAXN][2];
int n;
void clear() {
  cntE = 0;
  memset(H, -1, sizeof H);
}
void addedge(int u, int v) {
  E[cntE] = Edge(v, H[u]);
  H[u] = cntE++;
}
void dfs(int u) {
  long long maxv = -INF;
  long long sum = 0;
  int cnt = 0;
  for (int i = H[u]; ~i; i = E[i].n) {
    int v = E[i].v;
    dfs(v);
    if (dp[v][0] >= dp[v][1]) {
      sum += dp[v][0];
      maxv = max(maxv, dp[v][1] - dp[v][0]);
    } else {
      sum += dp[v][1];
      cnt ^= 1;
      maxv = max(maxv, dp[v][0] - dp[v][1]);
    }
  }
  if (cnt) {
    dp[u][0] = sum + maxv;
    dp[u][1] = max(sum + maxv + val[u], sum);
  } else {
    dp[u][0] = sum;
    dp[u][1] = val[u] + sum;
  }
}
void solve() {
  int u;
  clear();
  for (int i = (1); i <= (n); ++i) {
    scanf("%d%d", &u, &val[i]);
    if (~u) addedge(u, i);
  }
  dfs(1);
  printf("%I64d\n", max(dp[1][0], dp[1][1]));
}
int main() {
  while (~scanf("%d", &n)) solve();
  return 0;
}
