PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#LCA0000090. Cạnh ngắn nhất và dài nhất trên đường đi (Distance Query)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Cạnh ngắn nhất và dài nhất trên đường đi (Distance Query)
Distance Query
Source: SPOJ
Version: Phuoc Hung OJ Extended
Problem Statement
There are cities connected by undirected roads forming a tree. Each road has a positive integer length. For each query between distinct cities , find the minimum and maximum individual edge lengths on their unique path, not the total distance.
Input
First line: ; next lines: . Then and queries .
Output
For every query print two integers: the minimum and maximum edge lengths.
Subtasks
-
Subtask 1 (20 points): ; ; ; ; ; edges form a tree.
-
Subtask 2 (30 points): ; ; ; ; ; edges form a tree.
-
Subtask 3 (50 points): ; ; ; ; ; edges form a tree.
Examples
Input
5
2 3 100
4 3 200
1 5 150
1 3 50
3
2 4
3 5
1 2
Output
100 200
50 150
50 100
Explanation
Path uses edges and , so the result is . Path uses and ; path uses and .