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

#DSU0000064. Truy vấn đường đi duy nhất trên đồ thị một chu trình (Well-defined Path Queries on a Namori)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Truy vấn đường đi duy nhất trên đồ thị một chu trình (Well-defined Path Queries on a Namori)

Well-defined Path Queries on a Namori

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

You are given a connected undirected graph with nn vertices and exactly nn edges. There are no self-loops or duplicate edges. Such a graph contains exactly one simple cycle.

A simple path from xx to yy is a sequence of vertices starting at xx and ending at yy, with consecutive vertices connected by edges and no vertex visited more than once. Because the graph contains a cycle, two vertices may have more than one distinct simple path between them.

You are given qq queries, each specifying two distinct vertices x,yx,y. For each query, determine whether there is exactly one simple path between them. Queries do not modify the graph.

Input

Read nn, then exactly nn distinct edges ui,viu_i,v_i with ui<viu_i<v_i. Read qq, then qq query pairs xi,yix_i,y_i with xi<yix_i<y_i.

Output

Print Yes for a unique simple path, otherwise No, one answer per line.

Subtasks

  • Subtask 1 (20 points): 3≤n≤253\le n\le25, 1≤q≤2⋅1051\le q\le2\cdot10^5; 1≤ui<vi≤n1\le u_i<v_i\le n, 1≤xj<yj≤n1\le x_j<y_j\le n; the graph is simple, connected, and has exactly nn distinct edges.
  • Subtask 2 (30 points): 3≤n≤20003\le n\le2000, 1≤q≤2⋅1051\le q\le2\cdot10^5; 1≤ui<vi≤n1\le u_i<v_i\le n, 1≤xj<yj≤n1\le x_j<y_j\le n; the graph is simple, connected, and has exactly nn distinct edges.
  • Subtask 3 (50 points): 3≤n≤2⋅1053\le n\le2\cdot10^5, 1≤q≤2⋅1051\le q\le2\cdot10^5; 1≤ui<vi≤n1\le u_i<v_i\le n, 1≤xj<yj≤n1\le x_j<y_j\le n; the graph is simple, connected, and has exactly nn distinct edges.

Examples

Input

4
1 2
2 3
1 3
3 4
3
1 2
3 4
1 4

Output

No
Yes
No

Explanation

Vertices 1,2,31,2,3 are on the cycle, and vertex 44 lies in the tree attached to 33. Only pair (3,4)(3,4) has a unique simple path.