International Moonrabbit Organization
Time limit4sMemory limit1024 MB
Given a weighted tree, for each query (L, R, V) report the minimum, maximum, and sum of distances from base V to bases L through R.
- Level
Hard8 of 10
- Topics
- Tree, Divide and conquer, Binary search, Prefix sum
- Solved
- No attempts yet
Problem
Oktokki2, a bear living on the Moon, is the head of the venue reservation office at the International Moonrabbit Organization (IMO). So far, countries have each built one base on the Moon. The countries are numbered 1 through . To trade on the Moon, the bears built bidirectional roads, each connecting two bases. To save costs, only roads were built, and using only these roads, one can travel between any two bases. The roads are numbered 1 through . Road connects the base of country and the base of country , and walking along it takes seconds.
To celebrate the 100th anniversary of the IMO, meetings will be held every day for one year, starting on January 1, 2020. Year 2020 has days. The meeting on day is held at the base of country , and one bear from each base of countries through attends. To book the venue, Oktokki2 needs to know how many seconds after the start of day the bears arrive at the meeting. Every bear is diligent. Each bear leaves as soon as the day starts, walks to the venue along a shortest path, and returns to its original base immediately after the meeting. On each meeting day, Oktokki2 wants the arrival time of the earliest bear, the arrival time of the latest bear, and the sum of the arrival times of all bears attending.
Input
The first line contains and . ()
Each of the next lines contains , , and for road . (, )
It is guaranteed that any two bases can be reached from each other using only the given roads.
Each of the next lines contains , , and for the meeting on day . (, )
Output
For the meeting on day , let be the arrival time in seconds of the earliest bear, the arrival time in seconds of the latest bear, and the sum in seconds of the arrival times of all attending bears. On line , print , , and .