QOJ.ac

QOJ

Límite de tiempo: 2 s Límite de memoria: 512 MB Puntuación total: 100 Hackeable ✓

#5027. Star Wars

Estadísticas

In this round of interstellar warfare, our side has established $n$ outposts in the universe, connected by $m$ one-way wormholes. We classify all wormholes with destination $u$ as wormholes of outpost $u$.

Amidst the flames of war, these wormholes are difficult to maintain, and enemy strikes may come at any time. Effective strikes can be categorized into two types: 1. The enemy destroys a specific wormhole, which makes the two outposts it connects no longer directly reachable via this wormhole, but such a strike cannot destroy the two outposts it connects. 2. The enemy destroys a specific outpost. Since the main technology of the wormholes is concentrated at the exit, this causes all as-yet-undestroyed wormholes of that outpost to be destroyed simultaneously. However, wormholes originating from this outpost will not be destroyed.

Note: Destruction only makes a wormhole unavailable; it does not eliminate its existence.

To resist the enemy and maintain communication between various troops and outposts, we have developed two types of special forces responsible for repairing wormholes: Type A special forces can repair a specific wormhole. Type B special forces can repair all damaged wormholes of a specific outpost.

Considering the nature of enemy strikes, we have not stockpiled excessive strategic supplies at the outposts. Therefore, as long as one wormhole of an outpost is repaired and in an available state, that outpost is considered available.

We have mastered a rigorous spatial property. Utilizing this property, our warships can teleport along wormholes to the enemy camp to achieve precision strikes.

To seize the best opportunity for a counterattack, the command center must monitor all changes on the battlefield. To find a moment suitable for a counterattack, the commander-in-chief believes: If, starting from any of our outposts, one can perform infinite wormhole traversals (passing through the same outpost or wormhole multiple times) given a suitable route, then this outpost can achieve a counterattack. To make the process of wormhole traversal continuous and minimize the mass-energy loss of warships when switching wormholes at an outpost, an outpost can achieve continuous traversal if and only if there is exactly one available wormhole originating from that outpost. * If all our outposts can achieve a counterattack and all can also achieve continuous traversal, then this moment is an excellent moment for a counterattack.

The commander-in-chief has issued an order for you to use the real-time feedback from the battlefield to quickly tell him whether a counterattack can be launched at the current moment.

Input

The first line contains two positive integers $n, m$.

The next $m$ lines each contain two integers $u, v$, representing a wormhole from outpost $u$ to outpost $v$. It is guaranteed that $u \neq v$ and there are no two identical wormholes. Initially, all wormholes and outposts are intact.

The next line contains a positive integer $q$, representing the number of queries.

The next $q$ lines each represent a query or operation. First, read a positive integer $t$ representing the instruction type: If $t = 1$, the next two integers $u, v$ represent the enemy destroying the wormhole from outpost $u$ to outpost $v$. It is guaranteed that the wormhole exists and has not been destroyed. If $t = 2$, the next integer $u$ represents the enemy destroying outpost $u$. If all wormholes of this outpost have already been destroyed, this attack will have no effect. If $t = 3$, the next two integers $u, v$ represent our side repairing the wormhole from outpost $u$ to outpost $v$. It is guaranteed that the wormhole exists and has been destroyed. If $t = 4$, the next integer $u$ represents our side repairing outpost $u$. If the outpost has no destroyed wormholes, this repair will have no effect.

After each instruction is executed, you need to determine whether a counterattack can be launched. Output YES if it can, otherwise output NO.

Output

Output a total of $q$ lines. For each instruction, output whether a counterattack can be launched after the instruction is executed.

Examples

Input 1

3 6
2 3
2 1
1 2
1 3
3 1
3 2
11
1 3 2
1 2 3
1 1 3
1 1 2
3 1 3
3 3 2
2 3
1 3 1
3 1 3
4 2
1 3 2

Output 1

NO
NO
YES
NO
YES
NO
NO
NO
YES
NO
NO

Note

The wormhole status can be referred to in the image below, where the edges in the figure represent wormholes that exist and have not been destroyed:

Figure 1: Explanation of Example 1

Input 2

(input data)

Output 2

(output data)

Input 3

(input data)

Output 3

(output data)

Input 4

(input data)

Output 4

(output data)

Constraints

For all data, it is guaranteed that $1 \leq n \leq 5 \times 10^5$, $1 \leq m \leq 5 \times 10^5$, $1 \leq q \leq 5 \times 10^5$.

Test Case $n$ $m$ $q$ Special Constraints
1,2,3 $\leq 10$ $\leq 20$ $\leq 50$ None
4,5,6,7,8 $\leq 10^3$ $\leq 10^4$ $\leq 10^3$ None
9,10 $\leq 5 \times 10^5$ $\leq 5 \times 10^5$ $\leq 5 \times 10^5$ Guaranteed no $t = 2$ and $t = 4$ cases
11,12 $\leq 5 \times 10^5$ $\leq 5 \times 10^5$ $\leq 5 \times 10^5$ Guaranteed no $t = 4$ cases
13,14,15,16 $\leq 10^5$ $\leq 5 \times 10^5$ $\leq 5 \times 10^5$ None
17,18,19,20 $\leq 5 \times 10^5$ $\leq 5 \times 10^5$ $\leq 5 \times 10^5$ None

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.