#include <bits/stdc++.h>
using namespace std;
bool visited[200100];
long long p[200100];
vector<long long> g[200100];
long long dp[200100][2];
void dfs(long long u) {
  visited[u] = false;
  long long odd = -1, even = 0;
  for (long long i = 0; i < g[u].size(); i++)
    if (!visited[g[u][i]]) {
      long long v = g[u][i];
      dfs(v);
      long long nodd = max(odd == -1 ? 0 : odd + dp[v][0], even + dp[v][1]),
                neven = max(odd == -1 ? 0 : odd + dp[v][1], even + dp[v][0]);
      odd = nodd;
      even = neven;
    }
  dp[u][0] = even;
  dp[u][1] = max(odd, even + p[u]);
}
int main() {
  long long n;
  cin >> n;
  for (long long i = 0; i < n; i++) {
    long long v;
    cin >> v >> p[i];
    if (v == -1) continue;
    v--;
    g[v].push_back(i);
  }
  dfs(0);
  cout << max(dp[0][0], dp[0][1]);
  return 0;
}
