{"trustable":true,"prependHtml":"\u003cscript\u003e window.katexOptions \u003d { disable: true }; \u003c/script\u003e\n\u003cscript type\u003d\"text/x-mathjax-config\"\u003e\n MathJax.Hub.Config({\n tex2jax: {\n inlineMath: [[\u0027$$$\u0027,\u0027$$$\u0027], [\u0027$\u0027,\u0027$\u0027]],\n displayMath: [[\u0027$$$$$$\u0027,\u0027$$$$$$\u0027], [\u0027$$\u0027,\u0027$$\u0027]]\n }\n });\n\u003c/script\u003e\n\u003cscript async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS-MML_HTMLorMML\" type\u003d\"text/javascript\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"HTML","content":"\u003cdiv class\u003d\"panel_content\"\u003eIn the battlefield , an effective way to defeat enemies is to break their communication system.\u003cbr\u003eThe information department told you that there are n enemy soldiers and their network which have n-1 communication routes can cover all of their soldiers. Information can exchange between any two soldiers by the communication routes. The number 1 soldier is the total commander and other soldiers who have only one neighbour is the frontline soldier.\u003cbr\u003eYour boss zzn ordered you to cut off some routes to make any frontline soldiers in the network cannot reflect the information they collect from the battlefield to the total commander( number 1 soldier).\u003cbr\u003eThere is a kind of device who can choose some routes to cut off . But the cost (w) of any route you choose to cut off can’t be more than the device’s upper limit power. And the sum of the cost can’t be more than the device’s life m.\u003cbr\u003eNow please minimize the upper limit power of your device to finish your task.\u003cbr\u003e\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"The input consists of several test cases. \u003cbr\u003eThe first line of each test case contains 2 integers: n(n\u0026lt;\u003d1000)m(m\u0026lt;\u003d1000000).\u003cbr\u003eEach of the following N-1 lines is of the form:\u003cbr\u003eai bi wi\u003cbr\u003eIt means there’s one route from ai to bi(undirected) and it takes wi cost to cut off the route with the device.\u003cbr\u003e(1\u0026lt;\u003dai,bi\u0026lt;\u003dn,1\u0026lt;\u003dwi\u0026lt;\u003d1000)\u003cbr\u003eThe input ends with n\u003dm\u003d0.\u003cbr\u003e"}},{"title":"Output","value":{"format":"HTML","content":"Each case should output one integer, the minimal possible upper limit power of your device to finish your task. \u003cbr\u003eIf there is no way to finish the task, output -1."}},{"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 5\r\n1 3 2\r\n1 4 3\r\n3 5 5\r\n4 2 6\r\n0 0\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e3\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}