#P4383. [八省联考 2018] 林克卡特树
[八省联考 2018] 林克卡特树
Description
Little L has recently become obsessed with The Legend of Zelda: Breath of the Wild, and he especially enjoys the mini challenges.
In the game, there is a challenge called LCT. Its rules are as follows: There is a tree with nodes. Each edge has an integer weight . If , traversing this edge yields a gain of ; if , traversing this edge requires paying a toll of . Little L needs to control the protagonist Link to cut exactly edges from the tree, then connect new edges each with weight , producing a new tree. Next, he will choose two nodes on the tree, and walk from to along the unique simple path connecting them, paying tolls or obtaining gains for each edge he traverses.
The god of Hyrule, TemporaryDO, wants to test Link. He tells Link that if Link can cut appropriate edges and choose an appropriate path so that the total gain total toll is maximized, he will give him the legendary Master Sword.
Little L wants the Master Sword, so he asks you for help. Please tell him the maximum possible value of total gain total toll that Link can obtain.
Input Format
The first line contains two positive integers .
The next lines each contain three integers , indicating that the -th edge connects nodes and , and its weight is .
Output Format
Output a single integer, the answer.
5 1
1 2 3
2 3 5
2 4 -3
4 5 6
14
Hint
Sample Explanation: One possible optimal plan is: cut edge , add edge , and choose .
Constraints:
- For of the testdata, .
- For another of the testdata, .
- For another of the testdata, .
- For another of the testdata, .
- For the remaining testdata, there are no special constraints.
For all testdata, it is guaranteed that , , , , and .
Hint: This problem is not difficult.
Translated by ChatGPT 5
京公网安备 11011102002149号