// Arup Guha
// 4/14/2015
// Solution to 2012 NCPC Problem J: Juice

import java.util.*;

public class juice {

	public static node[] list;

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);
		int n = stdin.nextInt();

		// Read in the data.
		list = new node[n+1];
		int[] parents = new int[n+1];
		list[0] = new node(-1,0,10000000);
		for (int i=1; i<=n; i++) {
			parents[i] = stdin.nextInt();
			int myE = stdin.nextInt();
			int max = stdin.nextInt();
			list[i] = new node(parents[i], myE, max);
		}

		// Safe to add child links now.
		for (int i=1; i<=n; i++)
			list[parents[i]].kids.add(i);

		// Add up contributions from each separate tree directly connected to power.
		int res = 0;
		for (int i=0; i<list[0].kids.size(); i++)
			res += list[list[0].kids.get(i)].solve();

		// Here is our answer!
		System.out.println(res);
	}
}

class node {

	public int parent;
	public ArrayList<Integer> kids;
	public int energy;
	public int maxEnergy;
	public int[] best;

	public node(int myP, int myE, int max) {
		parent = myP;
		kids = new ArrayList<Integer>();
		energy = myE;
		maxEnergy = max;
		best = new int[maxEnergy+1];
	}

	// Wrapper function.
	public int solve() {
		solveRec();
		int ret = 0;
		for (int i=0; i<best.length; i++)
			ret = Math.max(ret, best[i]);
		return ret;
	}

	public void solveRec() {

		// Includes contribution of the root node only.
		for (int i=energy; i<=maxEnergy; i++)
			best[i] = 1;

		// Now, solve for each kid and add in answer into best.
		for (int i=0; i<kids.size(); i++) {
			juice.list[kids.get(i)].solve();
			best = combine(best, juice.list[kids.get(i)].best);
		}
	}

	// Returns the best answers by combining the best answers in cur and next.
	public static int[] combine(int[] cur, int[] next) {

		int[] res = new int[cur.length];

		// res[i] stores the max of cur[j]+next[k] with j+k = i.
		for (int i=0; i<cur.length; i++) {
			for (int j=0; j<next.length; j++) {
				if (i+j >= cur.length) break;
				res[i+j] = Math.max(res[i+j], cur[i]+next[j]);
			}
		}

		return res;
	}

}