#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
constexpr int MAX = 200010;
constexpr i64 INF = 0x3F3F3F3F3F3F3F3FLL;
int val[MAX];
i64 dp[MAX][3], buf[MAX][2];
vector<int> adj[MAX];
void dfs(int x) {
  for (const auto& y : adj[x]) {
    dfs(y);
  }
  buf[0][0] = 0;
  buf[0][1] = -INF;
  int i = 0;
  for (const auto& y : adj[x]) {
    ++i;
    buf[i][0] = max(buf[i - 1][0] + dp[y][0], buf[i - 1][1] + dp[y][1]);
    buf[i][1] = max(buf[i - 1][0] + dp[y][1], buf[i - 1][1] + dp[y][0]);
  }
  dp[x][0] = buf[i][0];
  dp[x][1] = max(buf[i][1], buf[i][0] + val[x]);
  dp[x][2] = buf[i][0] + val[x];
}
int main() {
  int n, p;
  while (~scanf("%d", &n)) {
    for (int i = 0; i < n; ++i) adj[i].clear();
    for (int i = 0; i < n; ++i) {
      scanf("%d%d", &p, &val[i]);
      if (~p) {
        adj[p - 1].push_back(i);
      }
    }
    dfs(0);
    i64 ans = 0;
    for (int i = 0; i < n; ++i) ans = max(ans, dp[i][1]);
    cout << ans << endl;
  }
  return 0;
}
