{"trustable":false,"sections":[{"title":"","value":{"format":"HTML","content":"\n \u003cdiv class\u003d\"problem_par\"\u003e\n \u003cdiv class\u003d\"problem_par_normal\"\u003e\n Let\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:\n \u003c/div\u003e\n \u003c/div\u003e\n \u003cdiv class\u003d\"problem_par_pre\"\u003e\n \u003ctable align\u003d\"CENTER\" cellspacing\u003d\"0\" cellpadding\u003d\"0\" border\u003d\"0\"\u003e\n \u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e2 5\n \\ / \n 3 4\n \\ /\n 1\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n \u003c/tbody\u003e\n \u003c/table\u003e\n \u003c/div\u003e\n \u003cdiv class\u003d\"problem_par\"\u003e\n \u003cdiv class\u003d\"problem_par_normal\"\u003e\n As 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. So 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. \n \u003c/div\u003e\n \u003c/div\u003e\n### 题意\u003cbr\u003e\n给你一棵二叉树, N 个顶点, 根为1,每个节点的编号为 1 − N ,各不相同。\n每条边有一个权值mi(苹果数) \n问你:这棵树在切割掉一些边后,最后只剩下 Q 条边,使得保留的边权和(苹果数)最大?\n\n*注:切割掉后还需要是根为1的一棵树。\n\n"}},{"title":"Input","value":{"format":"HTML","content":"\n \u003cdiv class\u003d\"problem_par\"\u003e\n \u003cdiv class\u003d\"problem_par_normal\"\u003e\n First line of input contains two numbers: \u003ci\u003eN\u003c/i\u003e and \u003ci\u003eQ\u003c/i\u003e (\u003cnobr\u003e\n 2 ≤ \n \u003ci\u003eN\u003c/i\u003e ≤ 100;\n \u003c/nobr\u003e \u003cnobr\u003e\n 1 ≤ \n \u003ci\u003eQ\u003c/i\u003e ≤ \n \u003ci\u003eN\u003c/i\u003e − 1\n \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.\n \u003c/div\u003e\n \u003c/div\u003e\n "}},{"title":"Output","value":{"format":"HTML","content":"\n \u003cdiv class\u003d\"problem_par\"\u003e\n \u003cdiv class\u003d\"problem_par_normal\"\u003e\n Output should contain the only number\u0026nbsp;— amount of apples that can be preserved. And don\u0027t forget to preserve tree\u0027s root ;-)\n \u003c/div\u003e\n \u003c/div\u003e\n "}},{"title":"Example","value":{"format":"HTML","content":"\u003cstyle type\u003d\"text/css\"\u003e TABLE.sample { border-collapse:collapse; border: solid 1px #1A5CC8; } TABLE.sample TR TD, TABLE.sample TR TH { border: solid 1px #1A5CC8; vertical-align: top; padding: 3px; } TABLE.sample TR TH { color: #1A5CC8; }\u003c/style\u003e\n \u003ctable class\u003d\"sample\"\u003e\n \u003ctbody\u003e\n \u003ctr\u003e\n \u003cth width\u003d\"350\"\u003einput\u003c/th\u003e\n \u003cth width\u003d\"350\"\u003eoutput\u003c/th\u003e\n \u003c/tr\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e5 2\n1 3 1\n1 4 10\n2 3 20\n3 5 20\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e21\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n \u003c/tbody\u003e\n \u003c/table\u003e\n "}}]}