// Arup Guha
// 5/17/2016
// Solution to 2016 NAIPC Problem D: Programming Team

import java.util.*;

public class d {

	public static int k;
	public static int n;
	public static emp[] tree;

	public static void main(String[] args) {

		// Read input.
		Scanner stdin = new Scanner(System.in);
		k = stdin.nextInt();
		n = stdin.nextInt();
		tree = new emp[n+1];
		tree[0] = new emp(0,0);
		for (int i=1; i<=n; i++) {
			int salary = stdin.nextInt();
			int prod = stdin.nextInt();
			int parent = stdin.nextInt();
			tree[parent].kids.add(i);
			tree[i] = new emp(salary, prod);
		}
		fillNodes(tree, 0);

		// Run a binary search.
		double low = 0, high = 10000;
		for (int iter=0; iter<50; iter++) {
			double mid = (low+high)/2;
			if (canSolve(mid))
				low = mid;
			else
				high = mid;
		}

		// Solve and output.
		System.out.printf("%.3f\n",low+1e-9);

	}

	public static boolean canSolve(double ratio) {
		double[] res = solveRec(ratio, 0);
		return res[k+1] >= -1e-9;
	}

	// Returns array of prod - ratio*sal array for this node.
	public static double[] solveRec(double ratio, int node) {

		// Store our answers here.
		double[] res = new double[Math.min(k+2, tree[node].numNodes+1)];
		Arrays.fill(res, -1000000000000000.0);
		res[0] = 0;

		// If we only have one node, it'll be the root.
		res[1] = tree[node].prod - ratio*tree[node].salary;

		// Leaf node.
		if (tree[node].numNodes == 1) return res;

		// Solve recursively, and also update our total solution.
		int used = 1;
		for (int i=0; i<tree[node].kids.size(); i++) {
			double[] kidRes = solveRec(ratio, tree[node].kids.get(i));
			used = update(res, used, kidRes);
		}

		// Return it.
		return res;
	}

	public static int update(double[] res, int used, double[] extra) {

		double[] tmp = new double[res.length];
		Arrays.fill(tmp, -1000000000000000.0);
		tmp[0] = 0;
		for (int i=1; i<=used; i++)
			for (int j=0; i+j<res.length && j<extra.length; j++)
				tmp[i+j] = Math.max(tmp[i+j], res[i]+extra[j]);

		int newused = Math.min(used + extra.length, res.length);

		for (int i=0; i<newused; i++)
			res[i] = tmp[i];

		return newused;
	}

	public static void fillNodes(emp[] tree, int node) {
		tree[node].numNodes = 1;
		for (int i=0; i<tree[node].kids.size(); i++) {
			int next = tree[node].kids.get(i);
			fillNodes(tree, next);
			tree[node].numNodes += tree[next].numNodes;
		}
	}
}

class emp {

	public int salary;
	public int prod;
	public ArrayList<Integer> kids;
	public int numNodes;

	public emp(int s, int p) {
		salary = s;
		prod = p;
		kids = new ArrayList<Integer>();
		numNodes = 0;
	}
}
