Cut Vertices and Bridges

Given a tree with N vertices and queries, report for each query whether a specified vertex is a cut vertex or a specified edge is a bridge.

Medium4TreeDFSGraphImplementationInterviewNo attempts yetTime limit1sMemory limit512 MB

Problem

In graph theory, a cut vertex and a bridge are defined as follows.

  • Cut vertex: if deleting a vertex splits the connected component that contained it into two or more components, that vertex is a cut vertex.
  • Bridge: if deleting an edge splits the connected component that contained it into two or more components, that edge is a bridge.

This problem asks for cut vertices and bridges of a tree. A tree is a graph with no cycle in which every vertex is connected.

Given a tree and a list of queries, answer each query.

Input

Input comes from standard input. The first line has the number of vertices NN of the tree. (2N1000002 \le N \le 100000) The vertices are numbered from 1 to NN. Each of the next N1N-1 lines has an edge aa and bb, meaning vertex aa and vertex bb are connected. The given graph is always a tree. (1a,bN1 \le a, b \le N)

The next line has the number of queries qq. (1q1000001 \le q \le 100000) Each of the next qq lines has a query tt and kk. (1t21 \le t \le 2) If tt is 1, the query asks whether vertex kk is a cut vertex. If tt is 2, the query asks whether the kk-th edge of the input is a bridge. When tt is 1, 1kN1 \le k \le N. When tt is 2, 1kN11 \le k \le N-1.

Output

Print to standard output. For the qq queries, print one answer per line. Print yes if the queried vertex is a cut vertex or the queried edge is a bridge, and no otherwise.