#LCA0000092. Đường ngắn nhất và dài nhất (Min Max Roads)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Đường ngắn nhất và dài nhất (Min Max Roads)
Min Max Roads
Source: LightOJ
Version: Phuoc Hung OJ Extended
Problem Statement
There are cities connected by undirected roads forming a tree. Each road has a positive integer cost.
For every query specifying two distinct cities , find the minimum and the maximum individual road costs along the unique path between them. Do not compute the total cost of the route.
Input
The first line contains . Next are edge lines , followed by and queries .
Output
Print lines, each containing the minimum and maximum edge cost in that order.
Subtasks
-
Subtask 1 (20 points): ; ; , for queries; ; edges form a tree.
-
Subtask 2 (30 points): ; ; , for queries; ; edges form a tree.
-
Subtask 3 (50 points): ; ; , for queries; ; edges form a tree.
Examples
Input
5
1 2 5
1 3 8
2 4 2
2 5 9
3
3 4
4 5
1 5
Output
2 8
2 9
5 9
Explanation
Path has edge costs , yielding 2 8. Path has costs , yielding 2 9. Path has costs , yielding 5 9.