#P10418. [蓝桥杯 2023 国 A] 相连的边
[蓝桥杯 2023 国 A] 相连的边
Problem Description
Given a tree with nodes, find edges such that the endpoints of these three edges can reach each other by traversing only these three edges, and the sum of the lengths of the three edges is as large as possible.
Input Format
The first line contains an integer , representing the number of nodes in the tree.
The next lines each contain two integers separated by a single space. In the -th line, the two numbers mean that there is an edge of length between node and node .
Output Format
Output one line containing one integer, representing the maximum possible sum of the lengths of the three edges that satisfy the requirement.
5
1 1
2 1
3 7
1 10
12
Hint
[Sample Explanation 1]
The edge length between node and node is , the edge length between node and node is , the edge length between node and node is , and the edge length between node and node is .
[Test Case Scale and Assumptions]
For of the test cases, .
For of the test cases, .
For all test cases, , , and .
Translated by ChatGPT 5