Antifreeze
Time limit2sMemory limit1024 MB
Given a weighted tree with heater rooms, answer whether two heater rooms can be linked by a chain of heater rooms where every gap is at most T.
- Level
Medium7 of 10
- Topics
- Tree, Union-find, Shortest path
- Solved
- No attempts yet
Problem
"In air so cold it stole my breath..."
The main building of Gyeonggi Science High School is a tree of classrooms connected by corridors. The corridor between classroom and classroom has length . () Normally every classroom has a heater running, but at this school only some classrooms do. (This is really true!!) is if the heater in classroom is off, and if it is on. () At least two classrooms have a working heater.
You start in a classroom with a working heater and want to reach another classroom with a working heater. Your temperature starts at and drops by every second. Your speed is , so you can think of your temperature dropping by the distance you walk. If the temperature becomes negative, you freeze to death. When you reach a classroom with a working heater, your temperature returns to . Reaching a classroom with a working heater at the exact moment the temperature is is allowed.
You must answer questions. The -th question is: can you travel from classroom to classroom without freezing? Both and are classrooms with a working heater.
Input
The first line contains the number of classrooms and the starting temperature , separated by a space.
The second line contains integers (), separated by spaces.
The next lines describe the corridors. Line () contains , , and , separated by spaces.
The next line contains the number of questions .
The next lines describe the questions. Line () contains and , separated by a space.
Output
Print lines. On line , print if you can reach from without freezing, and otherwise.
Constraints
- (). At least two classrooms have a working heater.
- , ()
- The graph given by the input is a tree.
- ()
- The distance between any two classrooms does not exceed .
- , , ()
- All numbers in the input are integers.