#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
template <typename T>
void write(T x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (x > 9) {
    write(x / 10);
  }
  putchar(x % 10 + '0');
}
template <typename T>
void read(T &x) {
  x = 0;
  char ch = getchar();
  long long f = 1;
  while (!isdigit(ch)) {
    if (ch == '-') f *= -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - 48;
    ch = getchar();
  }
  x *= f;
}
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int lcm(int a, int b) { return a / gcd(a, b) * b; };
long long ksm(long long a, long long n) {
  long long ans = 1;
  while (n) {
    if (n & 1) ans = ((ans % mod) * (a % mod)) % mod;
    a = ((a % mod) * (a % mod)) % mod;
    n >>= 1;
  }
  return ans % mod;
}
const long long maxn = 2e5 + 10;
long long n;
long long val[maxn];
long long dp[maxn][3];
struct Edge {
  long long to, next;
} e[maxn << 1];
long long head[maxn], cnt;
void add(long long x, long long y) {
  e[cnt].to = y;
  e[cnt].next = head[x];
  head[x] = cnt++;
}
void dfs(long long u, long long fa) {
  long long check = 0;
  dp[u][0] = 0, dp[u][1] = -0x3f3f3f3f;
  for (long long i = head[u]; ~i; i = e[i].next) {
    long long v = e[i].to;
    if (v == fa) continue;
    dfs(v, u);
    check = 1;
    long long t1 = dp[u][1], t2 = dp[u][0];
    dp[u][0] = max(t2 + dp[v][0], dp[v][1] + t1);
    dp[u][1] = max(t2 + dp[v][1], t1 + dp[v][0]);
  }
  if (check == 0) {
    dp[u][1] = val[u];
    dp[u][0] = 0;
    return;
  }
  dp[u][1] = max(dp[u][0] + val[u], dp[u][1]);
}
signed main() {
  read(n);
  memset(head, -1, sizeof(head));
  for (register long long i = 1; i <= n; ++i) {
    long long fa, a;
    read(fa), read(a);
    val[i] = a;
    if (fa == -1) continue;
    add(i, fa);
    add(fa, i);
  }
  dfs(1, -1);
  write(dp[1][1]);
  return 0;
}
