{"trustable":true,"sections":[{"title":"","value":{"format":"HTML","content":"\u003cdiv class\u003d\"problem_par\"\u003e\u003cdiv class\u003d\"problem_par_normal\"\u003eLet\u0027s imagine how apple tree looks in binary computer world. You\u0027re right, it looks just like a binary tree, i.e. any biparous branch splits up to exactly two new branches. We will enumerate by integers the root of binary apple tree, points of branching and the ends of twigs. This way we may distinguish different branches by their ending points. We will assume that root of tree always is numbered by 1 and all numbers used for enumerating are numbered in range from 1 to \u003ci\u003eN\u003c/i\u003e, where \u003ci\u003eN\u003c/i\u003e is the total number of all enumerated points. For instance in the picture below \u003ci\u003eN\u003c/i\u003e is equal to 5. Here is an example of an enumerated tree with four branches:\u003c/div\u003e\u003c/div\u003e\u003cdiv class\u003d\"problem_par_pre\"\u003e\u003ctable align\u003d\"CENTER\" cellspacing\u003d\"0\" cellpadding\u003d\"0\" border\u003d\"0\"\u003e\u003ctbody\u003e\u003ctr\u003e\u003ctd\u003e\u003cpre\u003e2 5\r\n \\ / \r\n 3 4\r\n \\ /\r\n 1\r\n\u003c/pre\u003e\u003c/td\u003e\u003c/tr\u003e\u003c/tbody\u003e\u003c/table\u003e\u003c/div\u003e\u003cdiv class\u003d\"problem_par\"\u003e\u003cdiv class\u003d\"problem_par_normal\"\u003eAs you may know it\u0027s not convenient to pick an apples from a tree when there are too much of branches. That\u0027s why some of them should be removed from a tree. But you are interested in removing branches in the way of minimal loss of apples.\r\nSo your are given amounts of apples on a branches and amount of branches that should be preserved. Your task is to determine how many apples can remain on a tree after removing of excessive branches.\r\n\u003c/div\u003e\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"\u003cdiv class\u003d\"problem_par\"\u003e\u003cdiv class\u003d\"problem_par_normal\"\u003eFirst line of input contains two numbers: \u003ci\u003eN\u003c/i\u003e and \u003ci\u003eQ\u003c/i\u003e (\u003cnobr\u003e2 ≤ \u003ci\u003eN\u003c/i\u003e ≤ 100;\u003c/nobr\u003e \u003cnobr\u003e1 ≤ \u003ci\u003eQ\u003c/i\u003e ≤ \u003ci\u003eN\u003c/i\u003e − 1\u003c/nobr\u003e). \u003ci\u003eN\u003c/i\u003e denotes the number of enumerated points in a tree. \u003ci\u003eQ\u003c/i\u003e denotes amount of branches that should be preserved. Next \u003ci\u003eN\u003c/i\u003e\u0026nbsp;−\u0026nbsp;1 lines contains descriptions of branches. Each description consists of a three integer numbers divided by spaces. The first two of them define branch by it\u0027s ending points. The third number defines the number of apples on this branch. You may assume that no branch contains more than 30000 apples.\u003c/div\u003e\u003c/div\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\u003cdiv class\u003d\"problem_par\"\u003e\u003cdiv class\u003d\"problem_par_normal\"\u003eOutput should contain the only number\u0026nbsp;— amount of apples that can be preserved. And don\u0027t forget to preserve tree\u0027s root ;-)\u003c/div\u003e\u003c/div\u003e"}},{"title":"Sample","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e5 2\r\n1 3 1\r\n1 4 10\r\n2 3 20\r\n3 5 20\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e21\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}