296 传统题

[ABC266F] 基环树唯一简单路径 (Well-defined Path Queries on a Namori)

时间限制
3000ms
内存限制
512MiB
登顶 / 尝试
0/ 0
难度
4

[ABC266F] 基环树唯一简单路径 (Well-defined Path Queries on a Namori)

Problem Statement

You are given a connected simple undirected graph GG with NN vertices numbered 11 to NN and NN edges. The ii-th edge connects Vertex uiu_i and Vertex viv_i bidirectionally.

Answer the following QQ queries.

  • Determine whether there is a unique simple path from Vertex xix_i to Vertex yiy_i (a simple path is a path without repetition of vertices).

Input

Input is given from Standard Input in the following format:

$N$
$u_1$ $v_1$
$u_2$ $v_2$
$\vdots$
$u_N$ $v_N$
$Q$
$x_1$ $y_1$
$x_2$ $y_2$
$\vdots$
$x_Q$ $y_Q$

Output

Print QQ lines.

The ii-th line (1≤i≤Q)(1 \leq i \leq Q) should contain Yes if there is a unique simple path from Vertex xix_i to Vertex yiy_i, and No otherwise.

Example

5
1 2
2 3
1 3
1 4
2 5
3
1 2
1 4
1 5
No
Yes
No

Note

  • Constraints:

  • 3≤N≤2×1053 \leq N \leq 2 \times 10^5

  • 1≤ui<vi≤N1 \leq u_i < v_i\leq N

  • (ui,vi)≠(uj,vj)(u_i,v_i) \neq (u_j,v_j) if i≠ji \neq j.

  • GG is a connected simple undirected graph with NN vertices and NN edges.

  • 1≤Q≤2×1051 \leq Q \leq 2 \times 10^5

  • 1≤xi<yi≤N1 \leq x_i < y_i\leq N

  • All values in input are integers.

  • Source: ABC266F