#include <bits/stdc++.h>
using namespace std;
int n, gs;
struct edge {
  int d, s;
} e[262144];
int lst[262144];
int v[262144];
long long f[262144][2];
long long tmp[2];
void addEdge(int x, int y) {
  e[++gs].d = y;
  e[gs].s = lst[x];
  lst[x] = gs;
}
void dfs(int u) {
  f[u][0] = 0;
  f[u][1] = -1e18;
  for (int i = lst[u]; i > 0; i = e[i].s) {
    int v = e[i].d;
    dfs(v);
    tmp[0] = max(f[u][0] + f[v][0], f[u][1] + f[v][1]);
    tmp[1] = max(f[u][0] + f[v][1], f[u][1] + f[v][0]);
    f[u][0] = tmp[0];
    f[u][1] = tmp[1];
  }
  f[u][1] = max(f[u][1], f[u][0] + v[u]);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    int p;
    scanf("%d%d", &p, v + i);
    if (p != -1) addEdge(p, i);
  }
  dfs(1);
  cout << max(f[1][0], f[1][1]) << endl;
  return 0;
}
