#P3398. 仓鼠找 sugar
仓鼠找 sugar
Description
The little hamster and his buddy sugar live in an underground cave, where each node is numbered . The cave forms a tree. One day, the little hamster plans to go from his bedroom () to the dining room (), while his buddy simultaneously goes from his bedroom () to the library (). They both take the shortest paths. Now the little hamster wants to know whether it is possible for them to meet somewhere along the way.
The little hamster is so weak and even gets abused by Master zzq every day. Please come save him!
Input Format
The first line contains two positive integers and , representing the number of nodes in the tree and the number of queries.
The next lines each contain two positive integers and , indicating that there is an edge between nodes and .
The next lines each contain four positive integers , , , and , representing a query as described above.
Output Format
For each query, if there exists a common point, output the uppercase letter Y; otherwise output N.
5 5
2 5
4 2
1 3
1 4
5 1 5 1
2 2 1 4
4 1 3 4
3 1 1 5
3 5 1 4
Y
N
Y
Y
Y
Hint
Time limit 1 s, memory limit 128 MB. Since the new judge is close to the NOIP judge in speed, please be aware of the impact of constant-factor overhead.
For 20% of the testdata, .
For 40% of the testdata, .
For 70% of the testdata, .
For 100% of the testdata, .
Translated by ChatGPT 5
京公网安备 11011102002149号