QOJ.ac

QOJ

حد الوقت: 2 s حد الذاكرة: 512 MB مجموع النقاط: 100

#16487. Key Point

الإحصائيات

Given a directed graph $G$ with $n$ nodes and $n-1$ directed edges, and a positive integer $k \le n$, it is guaranteed that the graph $G$ is connected when its edges are treated as undirected (i.e., it forms a tree).

There are $q$ operations. There are five types of operations, with parameters as follows:

  • 1 x y: Reverse the direction of the edge between node $x$ and node $y$. It is guaranteed that an edge exists between node $x$ and node $y$.
  • 2 a: Reverse the direction of all incoming edges of node $a$.
  • 3 b: Reverse the direction of all outgoing edges of node $b$.
  • 4 c: Reverse the direction of all incoming and outgoing edges of node $c$.
  • 5 p: Update the value of $k$ to $p$.

Here, an incoming edge of node $u$ is a directed edge ending at $u$, and an outgoing edge of node $u$ is a directed edge starting at $u$.

You need to maintain this directed graph and, before the first operation and after each operation, determine whether all nodes except node $k$ can reach node $k$ via the current directed edges. If so, output YES, otherwise output NO.

Input

The first line contains three integers $n, k, q$ ($2 \le n \le 10^6$, $0 \le q \le 10^6$, $1 \le k \le n$).

The next $n-1$ lines each contain two positive integers $u_i, v_i$, representing a directed edge from node $u_i$ to node $v_i$ ($1 \le u_i, v_i \le n$).

The next $q$ lines each contain 2 to 3 positive integers representing an operation. The meanings and formats are as defined above ($1 \le x, y, a, b, c, p \le n$).

It is guaranteed that the graph $G$ is connected when its edges are treated as undirected (i.e., it forms a tree), and it is guaranteed that an edge exists between node $x$ and node $y$ when performing the first type of operation.

Output

Output $q+1$ lines. Before the first operation and after each operation, determine whether all nodes except node $k$ can reach node $k$ via the current directed edges. If so, output YES, otherwise output NO.

Examples

Input 1

10 10 10
9 10
1 5
3 9
8 9
4 9
7 9
5 4
2 10
6 7
4 5
3 2
3 1
1 10 2
1 5 1
1 4 5
5 4
2 9
1 9 3
2 9

Output 1

YES
NO
NO
NO
NO
NO
YES
NO
NO
NO
NO

Input 2

10 4 10
8 9
2 4
10 5
9 4
3 2
1 2
5 4
6 4
7 8
1 2 1
1 2 1
5 10
1 5 4
1 10 5
3 4
1 5 4
5 2
1 5 10
1 4 5

Output 2

YES
NO
YES
NO
NO
YES
NO
YES
NO
NO
NO

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.