#P17138. [KOI 2026 #1] 步道
[KOI 2026 #1] 步道
Problem Description
There are rest stops on KOI Mountain, numbered from to , and undirected trails connecting these rest stops.
For each integer (), the crowding level of rest stop is given by a positive integer .
For each integer (), trail connects rest stop and rest stop (), and its length is . In other words, all rest stops are connected by these trails to form a tree.
The lonely hiker Gyojun wants to choose two different rest stops and walk along the unique simple path between them.
For a chosen path, define:
- as the sum of the lengths of all trails on the path.
- as the maximum crowding level among all rest stops on the path.
Gyojun wants to walk as far as possible and also enjoy a quiet walk where there are fewer people, so he defines the satisfaction of this path as .
Write a program to determine which two rest stops Gyojun should choose to maximize the satisfaction of the walking path.
Input Format
The first line contains an integer .
The second line contains integers , separated by spaces.
The third line contains integers , separated by spaces.
The fourth line contains integers , separated by spaces.
Output Format
Output two different rest stop indices on the first line, separated by a space, such that the satisfaction of the path between them is maximized.
If there are multiple valid answers, output any one of them.
2
1 2
2
1
1 2
4
6 10 20 1
2 4 4
3 21 15
1 3
Hint
Sample Explanation 1
The satisfaction of the path between rest stop and rest stop is , and this value is the maximum among all path satisfactions.
Sample Explanation 2
The satisfactions of all possible paths are as follows:
- The satisfaction of path is .
- The satisfaction of path is .
- The satisfaction of path is .
- The satisfaction of path is .
- The satisfaction of path is .
- The satisfaction of path is .
Constraints
- All numbers in the input are integers.
- .
- For each integer (), .
- For each integer (), and .
Subtasks
- ( points) .
- ( points) .
- ( points) .
- ( points) For each integer (), .
- ( points) .
- ( points) The number of distinct integers in the set is at most .
- ( points) No additional constraints.
Translated by ChatGPT-5.6.
Translated by ChatGPT 5