#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T _sq(T a) {
  return a * a;
}
template <class T>
inline T _sqrt(T a) {
  return (T)sqrt((double)a);
}
template <class T, class X>
inline T _pow(T a, X y) {
  T z = 1;
  for (int i = 1; i <= y; i++) {
    z *= a;
  }
  return z;
}
template <class T>
inline T _gcd(T a, T b) {
  a = abs(a);
  b = abs(b);
  if (!b) return a;
  return _gcd(b, a % b);
}
template <class T>
inline T _lcm(T a, T b) {
  a = abs(a);
  b = abs(b);
  return (a / _gcd(a, b)) * b;
}
template <class T>
inline T _extended(T a, T b, T &x, T &y) {
  a = abs(a);
  b = abs(b);
  T g, x1, y1;
  if (!b) {
    x = 1;
    y = 0;
    g = a;
    return g;
  }
  g = _extended(b, a % b, x1, y1);
  x = y1;
  y = x1 - (a / b) * y1;
  return g;
}
template <class T, class X>
inline bool getbit(T a, X i) {
  T t = 1;
  return ((a & (t << i)) > 0);
}
template <class T, class X>
inline T setbit(T a, X i) {
  T t = 1;
  return (a | (t << i));
}
template <class T, class X>
inline T resetbit(T a, X i) {
  T t = 1;
  return (a & (~(t << i)));
}
template <class T, class X>
inline T togglebit(T a, X i) {
  T t = 1;
  return (a ^ (t << i));
}
template <class T>
void pv(T v) {
  for (int i = 0; i < ((int)v.size()); i++) cout << v[i] << " ";
  cout << endl;
}
template <class T, class X>
inline T _bigmod(T n, X m) {
  unsigned long long ret = 1, a = n % 1000000007;
  while (m) {
    if (m & 1) ret = (ret * a) % 1000000007;
    m >>= 1;
    a = (a * a) % 1000000007;
  }
  ret %= 1000000007;
  return (T)ret;
}
template <class T>
inline T _modinv(T n) {
  return _bigmod(n, 1000000007 - 2);
}
long long p[(1000000 + 3)], w[(1000000 + 3)], n;
vector<int> adj[(1000000 + 3)];
pair<long long, long long> dp[(1000000 + 3)];
bool vis[(1000000 + 3)];
pair<long long, long long> go(int u) {
  pair<long long, long long> &ret = dp[u];
  if (vis[u]) return ret;
  vis[u] = 1;
  ret = make_pair(0ll, w[u]);
  pair<long long, long long> tmp = make_pair(0ll, -1e15);
  for (int i = 0; i < ((int)adj[u].size()); i++) {
    int v = adj[u][i];
    pair<long long, long long> store;
    store.first = max(tmp.first + go(v).first, tmp.second + go(v).second);
    store.second = max(tmp.first + go(v).second, tmp.second + go(v).first);
    tmp = store;
  }
  ret.first = max(ret.first, tmp.first);
  ret.second = max(ret.second, max(tmp.second, w[u] + tmp.first));
  return ret;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> p[i] >> w[i];
    if (p[i] != -1) adj[p[i]].push_back(i);
  }
  memset(dp, -1, sizeof dp);
  cout << max(go(1).first, go(1).second) << endl;
  return 0;
}
