{"trustable":true,"sections":[{"title":"题目描述","value":{"format":"MD","content":"有一棵二叉苹果树,如果树枝有分叉,一定是分两叉,即没有只有一个儿子的节点。这棵树共 $N$ 个节点,标号 $1$ 至 $N$,树根编号一定为 $1$。\n\n我们用一根树枝两端连接的节点编号描述一根树枝的位置。一棵有四根树枝的苹果树,因为树枝太多了,需要剪枝。但是一些树枝上长有苹果,给定需要保留的树枝数量,求最多能留住多少苹果。\n\n![tree.png](CDN_BASE_URL/e6da9844c9fcf932ffd508958f1aeec5?v\u003d1714338236)\n"}},{"title":"输入格式","value":{"format":"MD","content":"第一行两个数 $N$ 和 $Q$ ,$N$ 表示树的节点数,$Q$ 表示要保留的树枝数量。\r\n\r\n接下来 $N-1$ 行描述树枝信息,每行三个整数,前两个是它连接的节点的编号,第三个数是这根树枝上苹果数量。"}},{"title":"输出格式","value":{"format":"MD","content":"输出仅一行,表示最多能留住的苹果的数量。"}},{"title":"样例","value":{"format":"MD","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\n1 3 1\n1 4 10\n2 3 20\n3 5 20\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e21\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"数据范围与提示","value":{"format":"MD","content":"对于 $100\\%$ 的数据,$1\\le Q \\le N \\le 100, N\\neq 1$,每根树枝上苹果不超过 $30000$ 个。"}}]}