Under construction

Still being built. Things may change

Slicing Trees and Checking Paths

Interview

Time limit4sMemory limit1024 MB

Summary
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.
Level

Medium6 of 10

Topics
Tree, DFS
Solved
No attempts yet

Problem

A tree with NN vertices numbered from 11 to NN and N−1N-1 edges is given. You must answer the following QQ queries about this tree.

  • aa bb cc dd: Remove every edge on the shortest path from vertex aa to vertex bb. Print YES if a path from cc to dd still exists after the removal, and NO otherwise. Do not print the backticks.

Each query does not affect the others. The root of the tree is always vertex 11, and every edge is bidirectional.

Input

The first line contains NN and QQ, separated by a space. (2≤N≤100 0002\le N \le 100\,000; 1≤Q≤300 0001 \le Q \le 300\,000)

From the second line onward, each of the next N−1N-1 lines contains two vertex numbers uu and vv, separated by a space. This means there is a bidirectional edge connecting vertex uu and vertex vv. (1≤u,v≤N1 \le u, v \le N; u≠vu \ne v)

From line N+1N+1 onward, each of the next QQ lines contains four integers aa, bb, cc, and dd, separated by spaces. (1≤a,b,c,d≤N1 \le a, b, c, d \le N)

Output

Print QQ lines, one answer per query, in the same order as the queries.

Examples3

  1. Example 1

    Input
    8 4
    1 2
    1 3
    3 4
    3 5
    3 6
    4 7
    4 8
    6 7 2 3
    6 7 7 8
    4 6 1 5
    4 7 4 8
    
    Expected output
    YES
    NO
    YES
    YES
    
  2. Example 2

    Input
    2 2
    1 2
    1 1 2 2
    1 2 1 2
    
    Expected output
    YES
    NO
    
  3. Example 3

    Input
    19 6
    1 2
    1 3
    1 4
    1 5
    4 6
    4 7
    5 8
    5 9
    6 10
    6 11
    6 12
    9 13
    9 14
    9 15
    14 16
    15 17
    16 18
    16 19
    2 3 5 6
    5 11 8 15
    7 11 12 10
    9 14 16 19
    9 16 14 19
    12 17 14 11
    
    Expected output
    YES
    YES
    YES
    YES
    NO
    NO