#LCA0000056. Tập hợp khẩn cấp (Emergency Assembly)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Tập hợp khẩn cấp (Emergency Assembly)
Emergency Assembly
Source: Luogu
Version: Phuoc Hung OJ Extended
Problem Statement
On an island, assembly points are connected by undirected roads forming a tree. Traversing one road costs one coin.
Whenever an assembly is called, three people starting at points (possibly coincident) must choose one common assembly point . Their total cost is the sum of their path lengths to . Find a point minimizing this total and print the minimum cost.
Input
- The first line contains : numbers of points and assemblies.
- The next lines describe edges .
- The final lines each contain three starting positions .
Output
For each query, print two integers : a minimum-cost meeting point and the associated minimum total cost.
Subtasks
General constraints: ; .
-
Subtask 1 (20 points): ; .
-
Subtask 2 (30 points): ; .
-
Subtask 3 (50 points): ; .
Examples
Input
5 3
1 2
1 3
3 4
3 5
2 4 5
1 2 3
4 4 5
Output
3 4
1 2
4 2
Explanation
For , meeting at costs . For , meeting at costs . For , meeting at costs . These points minimize the respective total travel costs.