#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 0x3f3f3f3f;
const int NINF = 0x80808080;
const int maxn = 2e5 + 11;
int N, M, T, P, Q;
vector<int> G[maxn];
int f[maxn], p[maxn], vis[maxn];
long long dp[2][maxn];
long long dfs(bool odd, int u) {
  if (vis[u]) return dp[odd][u];
  vis[u] = 1;
  dp[0][u] = 0;
  dp[1][u] = NINF;
  for (int i = 0; i < G[u].size(); ++i) {
    int v = G[u][i];
    dfs(0, v);
    long long t1 = dp[0][u], t2 = dp[1][u];
    dp[0][u] = max(t1 + dp[0][v], t2 + dp[1][v]);
    dp[1][u] = max(t1 + dp[1][v], t2 + dp[0][v]);
  }
  dp[1][u] = max(dp[1][u], dp[0][u] + (long long)f[u]);
  return dp[odd][u];
}
int main() {
  cin >> N;
  for (int i = 1; i <= N; i++) {
    scanf("%d%d", &p[i], &f[i]);
    if (p[i] != -1) G[p[i]].push_back(i);
  }
  dfs(0, 1);
  cout << max(dp[0][1], dp[1][1]) << endl;
  return 0;
}
