import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Scanner; public class HiringEmployees_lewin { public static ArrayList[] child; public static int[] s, p, r, sz; public static int n, k; public static void main (String[] args) { Scanner in = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out, true); k = in.nextInt()+1; // include the CEO n = in.nextInt(); s = new int[n+1]; p = new int[n+1]; r = new int[n+1]; child = new ArrayList[n+1]; for (int i = 0; i <= n; i++) child[i] = new ArrayList<>(); for (int i = 1; i <= n; i++) { s[i] = in.nextInt(); p[i] = in.nextInt(); r[i] = in.nextInt(); child[r[i]].add(i); } sz = new int[n+1]; for (int i = n; i >= 0; i--) { sz[i] = 1; for (int next : child[i]) sz[i] += sz[next]; } double lo = 0, hi = 10000; for (int iter = 0; iter < 40; iter++) { double mid = (lo+hi) / 2.; if (can(mid)) lo = mid; else hi = mid; } out.printf("%.3f\n", lo); System.exit(0); } public static boolean can(double ratio) { double[][] dp = new double[n+1][]; for (int i = n; i >= 0; i--) { int cs = Math.min(k, sz[i]); dp[i] = new double[cs+1]; Arrays.fill(dp[i], -(1l<<60)); int last = 1; dp[i][1] = p[i] - ratio * s[i]; for (int next : child[i]) { for (int y = Math.min(last, cs); y >= 0; y--) { for (int x = 0; x+y <= cs && x < dp[next].length; x++) { dp[i][x+y] = Math.max(dp[i][x+y], dp[i][y] + dp[next][x]); } } last += dp[next].length; } dp[i][0] = 0; } return dp[0][k] >= 0; } }