#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void mini(T &a, T b) {
  if (b < a) a = b;
}
template <class T>
inline void maxi(T &a, T b) {
  if (b > a) a = b;
}
int n;
int a[200005];
vector<int> E[200005];
pair<long long, long long> solve(int u = 0) {
  vector<pair<long long, long long> > ans;
  for (auto v : E[u]) {
    ans.push_back(solve(v));
  }
  long long sum = 0;
  long long mn = 1LL << 60;
  int cnt = 0;
  for (pair<long long, long long> val : ans) {
    sum += max(val.first, val.second);
    mini(mn, abs(val.second - val.first));
    if (val.first < val.second) cnt++;
  }
  long long res1, res2;
  if (cnt & 1) {
    res2 = max(sum, sum - mn + a[u]);
    res1 = sum - mn;
  } else {
    res1 = sum;
    res2 = max(sum - mn, sum + a[u]);
  }
  return pair<long long, long long>(res1, res2);
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    int pi;
    scanf("%d %d", &pi, a + i);
    pi--;
    if (i) E[pi].push_back(i);
  }
  pair<long long, long long> ans = solve();
  cout << max(ans.first, ans.second) << endl;
}
