Regular Meeting
Time limit2sMemory limit512 MB
Given a weighted tree, for each query range of vertices S to E, find the meeting vertex that minimizes the largest bottleneck distance to the people in that range.
- Level
Medium7 of 10
- Topics
- Tree, Union-find, Segment tree
- Solved
- No attempts yet
Problem
A tree with vertices is given. Each vertex is numbered from 1 to in order. The -th edge connects vertex and vertex , and its weight is ().
The distance between two vertices in the tree is defined as the maximum edge weight on the shortest path connecting them. The distance between the same two vertices is defined as 0.
People living in the tree plan to hold meetings. The -th meeting is attended by people living at vertices numbered from to , inclusive. Each meeting takes place at some vertex in the tree. Choose so that the maximum distance from to any attendee is as small as possible.
Write a program that finds this minimum value.
Input
The first line contains two integers and , separated by a space. The next lines describe the edges. Line contains three integers , , and , separated by spaces, which means there is an edge of weight between vertex and vertex .
The next lines describe the meetings. Line contains two integers and , separated by a space, which describe the -th meeting.
Output
Print lines. The -th line contains the answer for the -th meeting.
Limits
- ()
- ()
- ()
- ()
- ()