Slicing Trees and Checking Paths
InterviewTime limit4sMemory limit1024 MB
Given a tree, for each query remove the edges on the path from a to b and report whether c and d are still connected.
Problem
A tree with vertices numbered from to and edges is given. You must answer the following queries about this tree.
- : Remove every edge on the shortest path from vertex to vertex . Print
YESif a path from to still exists after the removal, andNOotherwise. Do not print the backticks.
Each query does not affect the others. The root of the tree is always vertex , and every edge is bidirectional.
Input
The first line contains and , separated by a space. (; )
From the second line onward, each of the next lines contains two vertex numbers and , separated by a space. This means there is a bidirectional edge connecting vertex and vertex . (; )
From line onward, each of the next lines contains four integers , , , and , separated by spaces. ()
Output
Print lines, one answer per query, in the same order as the queries.