{"trustable":true,"prependHtml":"\u003cstyle type\u003d\"text/css\"\u003e\n #problem-body \u003e pre {\n display: block;\n padding: 9.5px;\n margin: 0 0 10px;\n font-size: 13px;\n line-height: 1.42857143;\n word-break: break-all;\n word-wrap: break-word;\n color: #333;\n background: rgba(255, 255, 255, 0.5);\n border: 1px solid #ccc;\n border-radius: 6px;\n }\n\u003c/style\u003e\n","sections":[{"title":"","value":{"format":"HTML","content":"\u003cdiv id\u003d\"problem-body\"\u003e\n\t\u003cp\u003eAfter the success of 2nd anniversary (take a look at problem \u003cb\u003eFTOUR\u003c/b\u003e for more details), this 3rd year, Travel Agent SPOJ goes on with another discount tour.\u003c/p\u003e\r\n\r\n\u003cp\u003e The tour will be held on \u003ci\u003eICPC\u003c/i\u003e island, a miraculous one on the Pacific Ocean. We list \u003cb\u003eN\u003c/b\u003e places (indexed from 1 to \u003cb\u003eN\u003c/b\u003e) where the visitors can have a trip. Each road connecting them has an \u003ci\u003einterest value\u003c/i\u003e, and this value can be \u003ci\u003enegative\u003c/i\u003e (if there is nothing interesting to view there). Simply, these \u003cb\u003eN\u003c/b\u003e places along with the roads connecting them form a \u003ci\u003etree structure\u003c/i\u003e. We will choose \u003ci\u003etwo places\u003c/i\u003e as the departure and destination of the tour.\u003c/p\u003e\r\n\r\n\u003cp\u003e Since September is the festival season of local inhabitants, some places are extremely crowded (we call them \u003ci\u003ecrowded places\u003c/i\u003e). Therefore, the organizer of the excursion hopes the tour will visit \u003ci\u003eat most \u003cb\u003eK\u003c/b\u003e crowded places\u003c/i\u003e (too tiring to visit many of them) and of course, the \u003ci\u003etotal number of interesting value\u003c/i\u003e should be maximum.\u003c/p\u003e\r\n\r\n\u003cp\u003eBriefly, you are given a map of \u003cb\u003eN\u003c/b\u003e places, an integer \u003cb\u003eK\u003c/b\u003e, and \u003cb\u003eM\u003c/b\u003e id numbers of \u003ci\u003ecrowded place\u003c/i\u003e. Please help us to find the optimal tour. Note that we can visit each place only \u003ci\u003eonce\u003c/i\u003e (or our customers easily feel bored), also the departure and destination places \u003ci\u003edon\u0027t need to be different\u003c/i\u003e.\u003c/p\u003e\r\n\r\n\u003ch3\u003eInput\u003c/h3\u003e\r\n\u003cp\u003eThere is exactly one case. First one line, containing 3 integers \u003cb\u003eN K M\u003c/b\u003e, with 1 \u0026lt;\u003d \u003cb\u003eN\u003c/b\u003e \u0026lt;\u003d 200000, 0 \u0026lt;\u003d \u003cb\u003eK\u003c/b\u003e \u0026lt;\u003d \u003cb\u003eM\u003c/b\u003e, 0 \u0026lt;\u003d \u003cb\u003eM\u003c/b\u003e \u0026lt;\u003d \u003cb\u003eN\u003c/b\u003e.\r\n\u003c/p\u003e\u003cp\u003eNext \u003cb\u003eM\u003c/b\u003e lines, each line includes an id number of a \u003ci\u003ecrowded place\u003c/i\u003e.\r\n\u003c/p\u003e\u003cp\u003eThe last (\u003cb\u003eN\u003c/b\u003e - 1) lines describe (\u003cb\u003eN\u003c/b\u003e - 1) two-way roads connected \u003cb\u003eN\u003c/b\u003e places, form \u003cb\u003ea b i\u003c/b\u003e, with \u003cb\u003ea, b\u003c/b\u003e is the id of 2 places, and \u003cb\u003ei\u003c/b\u003e is its \u003ci\u003einterest value\u003c/i\u003e (-10000 \u0026lt;\u003d \u003cb\u003ei\u003c/b\u003e \u0026lt;\u003d 10000).\r\n\r\n\u003c/p\u003e\u003ch3\u003eOutput\u003c/h3\u003e\r\n\u003cp\u003eOnly one number, the maximum total interest value we can obtain.\r\n\r\n\u003c/p\u003e\u003ch3\u003eExample\u003c/h3\u003e\r\n\r\n\u003cdiv\u003e\u003ctable class\u003d\"vjudge_sample\"\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\u003e8 2 3\r\n3\r\n5\r\n7\r\n1 3 1\r\n2 3 10\r\n3 4 -2\r\n4 5 -1\r\n5 7 6\r\n5 6 5\r\n4 8 3\r\n\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e12\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\u003c/div\u003e\r\n\r\n\u003ch3\u003eExplanation\u003c/h3\u003e\r\n\u003cp\u003eWe choose 2 and 6 as the departure and destination place, so the tour will be 2 → 3 → 4 → 5 → 6, total interest value \u003d 10 + (-2) + (-1) + 5 \u003d 12\r\n\u003cbr\u003e\r\n\u003cb\u003e* Added some unofficial cases\u003c/b\u003e\r\n\u003c/p\u003e\n\u003c/div\u003e"}}]}