PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#LCA0000064. Hai đường đi có gặp nhau? (Hamsters Find Sugar)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Hai đường đi có gặp nhau? (Hamsters Find Sugar)

Hamsters Find Sugar

Source: Luogu

Version: Phuoc Hung OJ Extended

Problem Statement

A hamster tunnel system is a tree of nn rooms. For each query, one hamster follows the unique shortest path from aa to bb, while another follows the path from cc to dd. Determine whether the two paths share at least one vertex. Arrival times are irrelevant.

Input

First line: n,qn,q, then n−1n-1 edges u vu\ v and qq queries a b c da\ b\ c\ d.

Output

For each query output Y if the paths intersect, otherwise N.

Subtasks

General constraints: 1≤n,q≤1051\le n,q\le 10^5; 1≤a,b,c,d,u,v≤n1\le a,b,c,d,u,v\le n; các cạnh tạo cây.

  • Subtask 1 (20 points): 1≤n≤401\le n\le 40; 1≤q≤501\le q\le 50.

  • Subtask 2 (30 points): 1≤n≤10001\le n\le 1000; 1≤q≤10001\le q\le 1000.

  • Subtask 3 (50 points): 1≤n≤1000001\le n\le 100000; 1≤q≤1000001\le q\le 100000.

Examples

Input

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

Output

Y
N
Y
Y
Y

Explanation

In the first query both paths are identical. In the second query the first path is just vertex 22, which does not lie on the path from 11 to 44, so the answer is N.