#P12180. DerrickLo's City (UBC002C)
DerrickLo's City (UBC002C)
Description
In a game, DerrickLo is operating a city. There are groups in this city. Since the relations between these groups are not very nice, DerrickLo needs to hold some meetings to relieve the relationships.
The city is constructed of towns indexed from to . There is exactly one group in each town. The group in town is indexed . The towns are linked with roads, so that every two towns can get to each other through these roads.
Every time DerrickLo holds a meeting, he will invite all the groups whose index is in an interval to a town , where town is the place of the meeting. Since the relations are not very nice, groups can not pass by a town whose group is also attending the meeting while going to town .
Because DerrickLo is new to this game, the task of determining town is handed to you.
Input Format
The first line contains two positive integers , the number of towns and the number of meetings.
There are two positive integers in the next lines, describing an edge which directly links town and . It's guaranteed that these roads forms a tree.
There are two positive integers in the next lines, which means that DerrickLo invites the groups indexed in to a meeting.
Output Format
For every meeting, if there exists such town , output Yes. Otherwise output No.
6 2
1 2
1 3
2 4
2 5
1 6
3 5
2 4
Yes
No
Hint
For the first meeting, the place of the meeting can be town , or .
For the second meeting, it can be proved that no matter which town is chosen, one of group will pass by the other's town.
京公网安备 11011102002149号