#include <bits/stdc++.h>
using namespace std;
template <typename T, typename V>
void bugp(const pair<T, V> &x) {
  cerr << '{' << x.first << ", " << x.second << '}' << endl;
}
template <typename T, typename U, typename V>
void bugpp(const pair<T, pair<U, V> > &x) {
  cerr << '{' << x.first << ", {" << x.second.first << ", " << x.second.second
       << "}}" << endl;
}
template <typename T>
bool maximize(T &x, const T &y) {
  if (x < y) {
    x = y;
    return 1;
  }
  return 0;
}
template <typename T>
bool minimize(T &x, const T &y) {
  if (x > y) {
    x = y;
    return 1;
  }
  return 0;
}
const int N = 200002;
int n, val[N];
long long dp[N][2], f[N][2];
vector<int> child[N];
void DFS(int u) {
  for (const int &v : child[u]) DFS(v);
  int v;
  for (int i = 0, _n = (child[u].size()); i < _n; ++i) {
    v = child[u][i];
    f[i + 1][0] = max(f[i][0] + dp[v][0], f[i][1] + dp[v][1]);
    f[i + 1][1] = max(f[i][0] + dp[v][1], f[i][1] + dp[v][0]);
  }
  dp[u][0] = f[child[u].size()][0];
  dp[u][1] = max(f[child[u].size()][1], f[child[u].size()][0] + val[u]);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 1, _n = (n); i <= _n; ++i) {
    int p;
    cin >> p >> val[i];
    if (p != -1) child[p].push_back(i);
  }
  f[0][1] = LLONG_MIN;
  DFS(1);
  cout << max(dp[1][0], dp[1][1]);
  return 0;
}
